Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pdi-scanner): use a smaller USB buffer in development #5551

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions libs/pdi-scanner/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
fn main() {
println!("cargo::rustc-check-cfg=cfg(production)");
println!("cargo:rerun-if-env-changed=NODE_ENV");

let is_production = match std::env::var("NODE_ENV") {
Ok(env) => env == "production",
Err(_) => false,
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I'm unsure about is whether we also need to consider whether this is a VxDev setup vs. true prod. On VxDev, NODE_ENV is production, but REACT_APP_VX_DEV is set to true so that we can distinguish it from true prod, e.g.

function shouldUseProdCerts(): boolean {
return isNodeEnvProduction() && !isVxDev() && !isIntegrationTest();
}

My quick sense is that, since VxDev isn't using VMs, it doesn't need the smaller buffer.

So all probably fine as is, just wanted to flag

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do the simpler version to start. If it turns out VxDev doesn't work, we can update it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup sounds right to me!


if is_production {
println!("cargo:rustc-cfg=production");
}
}
7 changes: 7 additions & 0 deletions libs/pdi-scanner/src/rust/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,15 @@ impl Scanner {
/// bit trying to catch the paper, we might need a bit more. So for any
/// reasonable paper size, 4 MB should be plenty and doesn't really put
/// a dent in available memory.
#[cfg(production)]
const BUFFER_SIZE: usize = 4_194_304;

/// For development, we want a smaller buffer because, for reasons we
/// don't understand, communicating with the scanner times out with a
/// larger buffer.
#[cfg(not(production))]
const BUFFER_SIZE: usize = 16_384;

let (host_to_scanner_tx, host_to_scanner_rx) =
mpsc::channel::<(usize, packets::Outgoing)>();
let (host_to_scanner_ack_tx, host_to_scanner_ack_rx) = mpsc::channel::<usize>();
Expand Down