Rust Systems & Async

20 lessons from merged PRs in Tokio, Tauri and Cargo, summarized in our own words. Async cancellation, IPC and build resolver pitfalls.

20 PR lessonstokio-rs/tokio · MIT (7)tauri-apps/tauri · Apache-2.0 OR MIT (7)rust-lang/cargo · Apache-2.0 OR MIT (6)
brain_seed_starter(instance_id="<your-brain-id>", stack="rust")

20 fixes from merged PRs

Every lesson below is a short summary in our own words and links to its upstream GitHub pull request in a permissive-licensed repository. Seed them into your Brain so your coding agent can find them when a similar problem comes up.

  1. tokio:pr-5812MITtokio-rs/tokio#5812 ↗
    Symptom

    tokio-util's WaitForCancellationFutureOwned is flagged as risky because its self-referential struct could trip stack-protector or aliasing assumptions.

    Cause and fix

    Cause: The future stores a reference to a Notify-derived Notified value that can outlive its owner, which counts as a possibly dangling reference and is formally undefined behavior. Fix: The Notified holder is now wrapped in a MaybeUninit-based maybe_dangling helper (new util module in tokio-util), and the cancellation token future uses it.

  2. tokio:pr-7856MITtokio-rs/tokio#7856 ↗
    Symptom

    A conflicting return statement inside a #[tokio::main] function makes rustc blame the wrong return expression in its type mismatch error.

    Cause and fix

    Cause: The macro expansion left the async block's output type to be inferred from the body, so the compiler reported the mismatch against an inferred type instead of the declared one. Fix: The macro in tokio-macros now passes the block through an identity function, check_output, which pins its output type to the declared return type; it adds no runtime cost.

  3. tokio:pr-6134MITtokio-rs/tokio#6134 ↗
    Symptom

    Tokio I/O resources can hang forever in rare cases when the driver reports readiness while an I/O operation is still in progress.

    Cause and fix

    Cause: Readiness clearing relied on one global driver tick, so a concurrent readiness update could be wiped out between the I/O attempt and the clear call. Fix: Each resource now keeps its own tick value in ScheduledIo instead of comparing against a single shared tick counter in the driver.

  4. tokio:pr-7122MITtokio-rs/tokio#7122 ↗
    Symptom

    On Windows, a tokio signal handler for ctrl_close, ctrl_logoff or ctrl_shutdown gets no time for async cleanup because the process dies right away.

    Cause and fix

    Cause: Windows terminates the process as soon as the console control handler routine returns for those events, so the handler cannot hand work to an async runtime and exit. Fix: The handler thread in signal/windows/sys.rs now never returns for those three events, so the process stays alive until normal Rust exit.

  5. tokio:pr-6647MITtokio-rs/tokio#6647 ↗
    Symptom

    tokio_util StreamReader and SinkWriter cannot be used together because the Sink impl of StreamReader demands a matching error type that never fits.

    Cause and fix

    Cause: The Sink impl bounded StreamReader<S, E> as if the second generic parameter were an error type, but that parameter is actually the buffer type. Fix: The bound on the buffer type parameter is removed from the passthrough Sink implementation in stream_reader.rs.

  6. tokio:pr-7910MITtokio-rs/tokio#7910 ↗
    Symptom

    The idle thread count of tokio's blocking pool metrics stays too high after the runtime shuts down.

    Cause and fix

    Cause: During shutdown a woken worker ran an extra inc_num_idle_threads call, so the counter was raised twice but lowered only once when the thread exited. Fix: The duplicate inc_num_idle_threads call in the shutdown branch of the blocking pool worker loop was deleted.

  7. tokio:pr-5803MITtokio-rs/tokio#5803 ↗
    Symptom

    Reading from a tokio File clone made with try_clone right after write_all completed sometimes returns empty data, mostly under heavy CPU load.

    Cause and fix

    Cause: File::try_clone did not notice a background write still running on the blocking pool, so the clone raced with that pending operation. Fix: File::try_clone now waits for any in-flight asynchronous operation on the original file before cloning, so later operations on the clone see the finished write.

  8. tauri:pr-15780Apache-2.0 OR MITtauri-apps/tauri#15780 ↗
    Symptom

    Android builds with tauri fail with a vague 'Failed to assemble APK' message when a very recent JDK such as 25 or 26 is installed.

    Cause and fix

    Cause: The bundled Gradle 8.14 cannot run on the newest Java versions, and nothing in the CLI told users about this mismatch. Fix: The Android env setup now detects the active Java version via java -version (JAVA_HOME first) and logs a warning when it exceeds a MAX_SUPPORTED_JAVA constant, without blocking the build.

  9. tauri:pr-1306Apache-2.0 OR MITtauri-apps/tauri#1306 ↗
    Symptom

    On Windows, a window created hidden and then maximized flashes briefly on screen when shown.

    Cause and fix

    Cause: Maximizing a hidden window applied the maximize immediately, which produced a visible flicker once the window appeared. Fix: In window_state.rs the maximize is deferred while the window is hidden on Windows; as a side effect, size and position queried while hidden return the pre-maximize values.

  10. tauri:pr-15344Apache-2.0 OR MITtauri-apps/tauri#15344 ↗
    Symptom

    tauri android builds use the newest NDK found under ANDROID_HOME/ndk even when NDK_HOME points at a specific version.

    Cause and fix

    Cause: The CLI ignored the NDK_HOME environment variable and always selected the latest installed NDK, or installed a default one if none existed. Fix: The Android mobile setup code now honors NDK_HOME when it is set and uses that NDK, logging the chosen path.

  11. tauri:pr-9952Apache-2.0 OR MITtauri-apps/tauri#9952 ↗
    Symptom

    A Tauri build fails with a vague parse error about no matching variant when a capability JSON file contains an invalid plugin name, giving no hint about the real problem.

    Cause and fix

    Cause: The capability file type is an untagged serde enum, which discards the specific inner error and only reports that no variant matched. Fix: Implemented Deserialize for the capability types with the serde_untagged crate, so the parse error now names the actual violated rule and its line and column.

  12. tauri:pr-15422Apache-2.0 OR MITtauri-apps/tauri#15422 ↗
    Symptom

    A Tauri NSIS installer built with signCommand still ships unsigned stock plugin DLLs such as System.dll and nsDialogs.dll, which some antivirus tools block.

    Cause and fix

    Cause: The bundler signed copies of the NSIS plugins in an output folder, but makensis was never told to look there and embedded the unsigned originals. Fix: installer.nsi and the NSIS bundler module now add the folder with the signed stock plugins via !addplugindir, so makensis embeds the signed DLLs.

  13. tauri:pr-1715Apache-2.0 OR MITtauri-apps/tauri#1715 ↗
    Symptom

    Loading Vite assets on Android in a Tauri dev session is extremely slow, with stalled connections taking up to 50 seconds.

    Cause and fix

    Cause: A single mutex was held for the whole time a custom protocol handler ran on Android, serializing asset requests. Fix: The wry code now clones the underlying handler and releases the mutex earlier, in the Android binding, lib.rs and the wkwebview module.

  14. tauri:pr-1275Apache-2.0 OR MITtauri-apps/tauri#1275 ↗
    Symptom

    On Android, Tauri plugin capabilities are denied for IPC calls made during page load, although the same permissions work on desktop.

    Cause and fix

    Cause: currentUrl was only assigned in onPageFinished, so IPC calls from scripts running earlier used an outdated URL when checking permissions. Fix: RustWebViewClient.kt now sets currentUrl in onPageStarted so it is current when frontend code starts calling IPC.

  15. cargo:pr-16566Apache-2.0 OR MITrust-lang/cargo#16566 ↗
    Symptom

    Running cargo init inside the home directory silently creates a Cargo.toml there, which later confuses package discovery from every subdirectory.

    Cause and fix

    Cause: cargo init had no guard against targeting the home directory, so the whole home folder could become a package root. Fix: cargo_new.rs now makes cargo init fail in the home directory and suggests running cargo init with an explicit path.

  16. cargo:pr-16623Apache-2.0 OR MITrust-lang/cargo#16623 ↗
    Symptom

    When cargo install fails and build.build-dir differs from the target directory, the hint about where intermediate artifacts live names the wrong folder.

    Cause and fix

    Cause: The message always pointed to the target directory, but intermediate artifacts are stored in the build directory. Fix: The failure message in cargo_install.rs now refers to the configured build-dir path and its matching environment variable.

  17. cargo:pr-15525Apache-2.0 OR MITrust-lang/cargo#15525 ↗
    Symptom

    With -Zpackage-workspace, cargo publish --workspace aborts entirely if any member has publish = false.

    Cause and fix

    Cause: Workspace publishing treated unpublishable members as errors instead of members to leave out. Fix: When publishing a whole or virtual workspace, cargo now skips packages marked publish = false and publishes the rest, while a direct publish of such a package still errors.

  18. cargo:pr-16220Apache-2.0 OR MITrust-lang/cargo#16220 ↗
    Symptom

    A list-valued cargo setting from an environment variable overrides the same setting passed with --config on the command line.

    Cause and fix

    Cause: Non-mergeable list values were resolved with the environment variable taking priority, which was an oversight when that list type was introduced. Fix: The config lookup in util/context/mod.rs now lets the --config CLI value take precedence over the environment variable for non-mergeable lists.

  19. cargo:pr-16513Apache-2.0 OR MITrust-lang/cargo#16513 ↗
    Symptom

    Switching -Zno-embed-metadata on or off does not trigger a rebuild, and rustc then complains about missing rmeta files.

    Cause and fix

    Cause: The flag was not part of the fingerprint, so cached build outputs from the other mode were considered fresh. Fix: The -Zno-embed-metadata value is now mixed into the general config hash in fingerprint/mod.rs.

  20. cargo:pr-14860Apache-2.0 OR MITrust-lang/cargo#14860 ↗
    Symptom

    cargo with net.git-fetch-with-cli = true fails to clone a git dependency into its cache with 'cannot use bare repository' on recent git.

    Cause and fix

    Cause: Cargo removed GIT_DIR before invoking git, and newer git defaults safe.bareRepository to explicit and refuses implicit bare repos. Fix: In sources/git/utils.rs cargo now sets GIT_DIR to the actual repository path for the CLI fetch instead of unsetting it.

Explain it once. Every AI knows it. By default, no generative AI model reads or rewrites your lessons. A small ranking model in the EU only scores them. Starter lessons never overwrite your team's own project lessons.