Skip to content

Fixes usdt feature dependency resolution bug - #491

Closed
bnaecker wants to merge 6 commits into
mainfrom
fix/dependency-resolution-fail
Closed

bnaecker wants to merge 6 commits into
mainfrom
fix/dependency-resolution-fail

Conversation

@bnaecker

@bnaecker bnaecker commented Dec 8, 2021

Copy link
Copy Markdown
Collaborator
  • Adds the Dropshot usdt-probes feature to every crate depending on
    both Dropshot and slog-dtrace. Leaving this feature out causes build
    failures when compiling packages individually, as the selected usdt
    feature actually includes inline assembly, but Dropshot does not
    include the right feature-selection crate attribute. This works when
    building the whole workspace, since all features are unioned.
  • Adds a check subcommand to omicron-package, that runs cargo check instead of cargo build. This is also run during CI now, to
    catch regressions here, at least for the crates that we package via
    omicron-package.

@bnaecker
bnaecker force-pushed the fix/dependency-resolution-fail branch from ecde953 to 06fce79 Compare December 8, 2021 19:17
Comment thread .github/workflows/rust.yml Resolved
Comment thread .github/workflows/rust.yml Resolved
@bnaecker
bnaecker force-pushed the fix/dependency-resolution-fail branch from 06fce79 to de5ed00 Compare December 8, 2021 19:29
- Adds the Dropshot `usdt-probes` feature to every crate depending on
  both Dropshot and `slog-dtrace`. Leaving this feature out causes build
  failures when compiling packages individually, as the selected `usdt`
  feature actually includes inline assembly, but Dropshot does not
  include the right feature-selection crate attribute. This works when
  building the whole workspace, since all features are unioned.
- Adds a `check` subcommand to `omicron-package`, that runs `cargo
  check` instead of `cargo build`. This is also run during CI now, to
  catch regressions here, at least for the crates that we package via
  `omicron-package`.

@davepacheco davepacheco left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We talked about this a bunch offline and discussed some alternative solutions. If it's useful to land this PR in the meantime, that works, or we could revert the slog-dtrace change for now.

- name: Check style
run: cargo fmt -- --check

check-omicron-deployment:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I wonder if this will be a lot slower (or faster?) than making this a step in the build-and-test job. As a step in the build-and-test job, we may not need to rebuild as many things. But maybe the point is to rebuild them, and this will be run by GitHub in parallel, so maybe it doesn't matter?

@bnaecker

bnaecker commented Dec 8, 2021 •

Copy link
Copy Markdown
Collaborator Author

I'd like to add some more context here, to help illuminate the actual cause of this problem. Prior to this, building a crate like omicron-sled-agent fails with the following:

bnaecker@shale : ~/omicron $ cargo build -p omicron-sled-agent
   Compiling dropshot v0.6.1-dev (https://github.com/oxidecomputer/dropshot?branch=main#ff33033a)
   Compiling propolis-client v0.1.0 (https://github.com/oxidecomputer/propolis?rev=00ec8cf18f6a2311b0907f0b16b0ff8a327944d1#00ec8cf1)
error[E0658]: use of unstable library feature 'asm': inline assembly is not stable enough for use and is subject to change
   --> /home/bnaecker/.cargo/git/checkouts/dropshot-a4a923d29dccc492/ff33033/dropshot/src/lib.rs:574:1
    |
574 |   #[usdt::provider(provider = "dropshot")]
    |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
   ::: /home/bnaecker/.cargo/git/checkouts/dropshot-a4a923d29dccc492/ff33033/dropshot/src/server.rs:387:13
    |
387 | /             probes::request_finish!(|| {
388 | |                 crate::ResponseInfo {
389 | |                     id: request_id.parse().unwrap(),
390 | |                     local_addr,
...   |
394 | |                 }
395 | |             });
    | |______________- in this macro invocation
    |
    = note: see issue #72016 <https://github.com/rust-lang/rust/issues/72016> for more information
    = help: add `#![feature(asm)]` to the crate attributes to enable
    = note: this error originates in the macro `probes::request_finish` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0658]: use of unstable library feature 'asm': inline assembly is not stable enough for use and is subject to change
   --> /home/bnaecker/.cargo/git/checkouts/dropshot-a4a923d29dccc492/ff33033/dropshot/src/lib.rs:574:1
    |
574 |   #[usdt::provider(provider = "dropshot")]
    |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
   ::: /home/bnaecker/.cargo/git/checkouts/dropshot-a4a923d29dccc492/ff33033/dropshot/src/server.rs:361:13
    |
361 | /             probes::request_finish!(|| {
362 | |                 crate::ResponseInfo {
363 | |                     id: request_id.clone(),
364 | |                     local_addr,
...   |
368 | |                 }
369 | |             });
    | |______________- in this macro invocation
    |
    = note: see issue #72016 <https://github.com/rust-lang/rust/issues/72016> for more information
    = help: add `#![feature(asm)]` to the crate attributes to enable
    = note: this error originates in the macro `probes::request_finish` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0658]: use of unstable library feature 'asm': inline assembly is not stable enough for use and is subject to change
   --> /home/bnaecker/.cargo/git/checkouts/dropshot-a4a923d29dccc492/ff33033/dropshot/src/lib.rs:574:1
    |
574 |   #[usdt::provider(provider = "dropshot")]
    |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
   ::: /home/bnaecker/.cargo/git/checkouts/dropshot-a4a923d29dccc492/ff33033/dropshot/src/server.rs:331:5
    |
331 | /     probes::request_start!(|| {
332 | |         let uri = request.uri();
333 | |         crate::RequestInfo {
334 | |             id: request_id.clone(),
...   |
340 | |         }
341 | |     });
    | |______- in this macro invocation
    |
    = note: see issue #72016 <https://github.com/rust-lang/rust/issues/72016> for more information
    = help: add `#![feature(asm)]` to the crate attributes to enable
    = note: this error originates in the macro `probes::request_start` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0658`.
error: could not compile `dropshot` due to 3 previous errors
warning: build failed, waiting for other jobs to finish...
error: build failed

This is because of an unfortunate combination of how features are unified and some of the internals of the usdt crate itself.

Specifically, 5519e936 introduced a dependency on slog-dtrace. This also depends on usdt and enables its (default) feature called asm. That causes the crate to generate macros that contain the asm! macro, which, being unstable, requires opting into with a crate-level attribute of #![feature(asm)].

Sled agent also depends on dropshot, but without its feature called usdt-probes. That causes dropshot to be compiled "as if" the usdt/asm feature is not enabled. In this case, dropshot does not use the #![feature(asm)] attribute, since that's written behind a cfg_attr guard.

Nowusdt has been included via dropshot without the asm feature, but via slog-dtrace with the asm feature. Because features are unioned, this really means the asm feature is enabled. dropshot doesn't "think" that's the case, so it doesn't include the #![feature(asm)], so it includes macros that actually expand to asm! without the right attribute. Thus the build failure.

Now, why didn't we see this in CI? CI only builds the entire workspace, which takes the union of all features for all dependencies. One dependency, nexus, selected the usdt-probes feature, which at the workspace level is equivalent to it being selected by all crates that depend on dropshot.

Solutions

This issue is caused by a complex confluence of multiple things: feature resolution, unstable/nightly Rust, and declarative macros. As is, it's not possible to write the correct set of feature flags in any one package, since that depends on both where the package is included, and whether it's built as a single package or as part of a workspace.

But there are some ideas. One is to change usdt to use functions rather than macros. We selected macros to make sure we got as close as possible to the "zero disabled probe effect" that DTrace shoots for: function calls may or may not be inlined, and we didn't want to rely on the compiler to ensure that. Now might be a time to validate whether (1) this function call is ever not inlined, and (2) whether we care. The function will likely only contain a single asm! statement, which seems like it should be a candidate for inlining, but we'll never be as sure as with the macro.

Another idea is to change how library crates like dropshot refer to usdt items. In particular, dropshot's usdt-probes feature "forwards" the asm feature from usdt, and selects a no-op implementation of usdt if usdt-probes is not chosen. But it still refers to the generated probe macros regardless -- the fact that they're now no-ops is irrelevant. And because of the unioning of features, it's actually a problem. Someone could still get the dropshot probes, even if they really, truly did not want them, just because another crate that also depends on usdt enabled them.

Instead, dropshot, and any library crate that wants to expose probes behind a feature flag, could put all references to the generated probe macros behind a conditional compilation directive. Something like:

#[cfg(feature = "usdt-probes")]
probes::my_probe_macro!();

Now that probe would not even be referred to in the final binary if the usdt-probes feature isn't enabled. This is really much closer to the desired intent, and integrates better with the way Cargo unifies features in general, by preventing how some other dependency chooses usdt features from impacting how dropshot uses them.

I've tested that this latter approach works, by patching dropshot locally. The build command at the top of this comment works fine in that case. I plan to push an updated version to Dropshot soon.

cc @ahl @davepacheco @smklein

duplicated in the rust-toolchain.toml file.
Comment thread rust-toolchain.toml Resolved
Comment thread oximeter/collector/Cargo.toml Resolved
@bnaecker

bnaecker commented Dec 9, 2021

Copy link
Copy Markdown
Collaborator Author

Note: This PR also deliberately enables Dropshot's USDT probes in all packages that consume it as a dependency.

@bnaecker
bnaecker requested a review from davepacheco December 9, 2021 00:46
@bnaecker
bnaecker enabled auto-merge (squash) December 9, 2021 01:51
@bnaecker
bnaecker force-pushed the fix/dependency-resolution-fail branch from bd8f6f5 to a5b9945 Compare December 9, 2021 03:53
@bnaecker

bnaecker commented Dec 9, 2021 •

Copy link
Copy Markdown
Collaborator Author

I seem to be stuck in the third circle of hell, which is GitHub continually reporting Expected - waiting for status to be reported for the two build-and-test checks. I'm going to close and reopen this PR next, to see if that convinces GH that I mean business.

@bnaecker bnaecker closed this Dec 9, 2021
auto-merge was automatically disabled December 9, 2021 04:22

Pull request was closed

@bnaecker bnaecker reopened this Dec 9, 2021
@bnaecker

bnaecker commented Dec 9, 2021

Copy link
Copy Markdown
Collaborator Author

I am increasingly frustrated. The required status checks are actually running on the individual commits, but somehow this is not equivalent to the check passing for the PR itself. I am going nuclear, and will be closing this PR, deleting the remote branch, and reopening a new PR. The other "solutions" I've found by searching suggest removing the branch protection rules that require the status checks in the first place, which I have neither the permissions nor inclination to do.

@bnaecker bnaecker closed this Dec 9, 2021
@bnaecker
bnaecker deleted the fix/dependency-resolution-fail branch December 9, 2021 04:41
@bnaecker

bnaecker commented Dec 9, 2021

Copy link
Copy Markdown
Collaborator Author

Well, after that spectacularly unproductive bout of force-pushing, this PR has been continued as #496. The status checks still refuse to report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants