Skip to content

Fix nested client filesync incorrect deduplication - #7943

Merged
sipsma merged 4 commits into
dagger:mainfrom
sipsma:fix-filesync-dedupe
Jul 23, 2024
Merged

sipsma merged 4 commits into
dagger:mainfrom
sipsma:fix-filesync-dedupe

Conversation

@sipsma

@sipsma sipsma commented Jul 16, 2024 •

Copy link
Copy Markdown
Contributor

As detailed in #7900, certain obscure corner cases can result in
separate clients on separate hosts (or separate nested exec containers)
from re-using each others' filesync cache refs unexpectedly and, if
files happen to match metadata precisely, end up with incorrect
file contents being used in the sync.

The requirements for this to happen are as obscure as it gets, but it is
impacting our CI and causing flakes, so needs a fix. It is technically
possible for users to hit this too, so may as well solve it for them.

Previously part of the cause here was that we used hostname as a
semi-stable host identifier, but nested clients mostly have the same
default container hostname.

  • There was much more to it than this, but this is the part we can
    address.

The fix here replaces the hostname with an ID that is persisted in the
client's XDG state dir (i.e. ~/.local/state/dagger/). It's random when
newly initialized but re-used after that.

That solves this problem for non-nested clients. For nested clients, we
just set this to a random ID in each exec for now.

  • It would also be possible to try to persist this in the nested exec,
    but it's not clear yet if that's worth the complication in that case,
    so keeping it simple for now.

@sipsma

sipsma commented Jul 16, 2024 •

Copy link
Copy Markdown
Contributor Author

Thought of a potentially even simpler fix to #7900 than what I described in the most recent comment there: just set the hostname of nested clients to a digest of their call.

Ah, I actually just remembered that there's a really big tradeoff with relying on hostnames (separate from ones I originally had in mind), which is that it results in CNI network namespaces not being re-usable, which adds likely meaningful performance overhead...

I guess I will just go with the persistent host identifier approach after all.

Also, on my first try here I did get a flake in the TestPythonProjectLayout tests still 😢 Was hoping that one might have been the same as #7900 (which is about TestLegacy), but either it isn't or there was something wrong about the "unique hostname" approach. Will see what happens after I switch approaches I guess.

@sipsma
sipsma force-pushed the fix-filesync-dedupe branch from cc23177 to 049be82 Compare July 17, 2024 01:36
sipsma added 3 commits July 18, 2024 17:45
This were hidden from the normal Debug log level during previous
attempts to de-noise our logs, but in retrospect they aren't *that*
noisy and are generally very useful for understanding when filesync and
cache volume refs are being re-used vs. newly initialized. That in turn
helps understand all sorts of performance-related behavior and is just
generally useful for debugging.

Signed-off-by: Erik Sipsma <[email protected]>
Including the caller client ID, the call itself and the nested client id
for a given container execution can be extremely useful for following
the progression of nested client/module execution in the logs.

Signed-off-by: Erik Sipsma <[email protected]>
These logs only show up on ExtraDebug level but can still be useful when
it's hard to get output from various internal processes (like codegen
containers).

Before this, nested clients were getting these logs cutoff early because
the context was getting canceled after the first request that initializes
the client ended.

Now, the logs will continue printing until the session as a whole is
cleaned up.

Signed-off-by: Erik Sipsma <[email protected]>
@sipsma
sipsma force-pushed the fix-filesync-dedupe branch 2 times, most recently from 922b875 to f80f961 Compare July 19, 2024 01:00
@sipsma

sipsma commented Jul 19, 2024

Copy link
Copy Markdown
Contributor Author

Currently letting TestLegacy run in a loop for a good while to verify flake is gone. Will do the same for the module tests as a whole. GHA is having an incident right now, but once that's recovered will do re-runs in CI too to check.

@sipsma
sipsma marked this pull request as ready for review July 19, 2024 02:59
@sipsma
sipsma marked this pull request as draft July 19, 2024 02:59
@sipsma

sipsma commented Jul 19, 2024

Copy link
Copy Markdown
Contributor Author

Locally:

  • TestLegacy passed in a loop for an hour
  • TestModule has passed twice in a row (takes ~30m locally, so gonna keep it looping for a while longer)

In CI:

So at least seems to have fixed the expected flake, though sad the others are still going to require their own investigation.

Gonna keep looping in CI a bit more to be extra sure.

@sipsma
sipsma force-pushed the fix-filesync-dedupe branch 2 times, most recently from a36aff7 to 9f35308 Compare July 19, 2024 05:37
@sipsma
sipsma marked this pull request as ready for review July 19, 2024 05:41
@sipsma sipsma changed the title [WIP] Fix nested client filesync incorrect deduplication Fix nested client filesync incorrect deduplication Jul 19, 2024
@sipsma
sipsma force-pushed the fix-filesync-dedupe branch from 9f35308 to 515ec69 Compare July 19, 2024 16:37
@sipsma

sipsma commented Jul 19, 2024

Copy link
Copy Markdown
Contributor Author

Had to do lots of re-runs after other unrelated flakes, but never saw TestLegacy flake in CI either, so feel good it's gone.

@sipsma
sipsma requested review from jedevc and vito July 22, 2024 16:32

@jedevc jedevc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Aside from the note that this likely won't work on windows right now (haven't tested to be sure), this looks good to me 🎉

insane deep dive, nice job 🥳

Comment thread engine/client/stableid.go Outdated
defer os.Remove(tmpFile.Name())
defer tmpFile.Close()

if err := tmpFile.Chown(uid, gid); err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hello, welcome to windows hell again 🎉 File.Chown always fails on Windows: https://pkg.go.dev/os#File.Chown 😱

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oi, I had not encountered that "fun" fact previously, thanks for the pointer! I'll patch this up quick; I actually can drop the chown for now. It was added in an earlier iteration where I was trying to run this code in nested execs too (and thus needed to deal with different uid/gid), but I ended up backing out of that for simplicity.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in force push

As detailed in issue 7900, certain obscure corner cases can result in
separate clients on separate hosts (or separate nested exec containers)
from re-using each others' filesync cache refs unexpectedly and, if
files happen to match metadata precisely, end up with incorrect
file contents being used in the sync.

The requirements for this to happen are as obscure as it gets, but it is
impacting our CI and causing flakes, so needs a fix. It is *technically*
possible for users to hit this too, so may as well solve it for them.

Previously part of the cause here was that we used hostname as a
semi-stable host identifier, but nested clients mostly have the same
default container hostname.
* There was much more to it than this, but this is the part we can
  address.

The fix here replaces the hostname with an ID that is persisted in the
client's XDG state dir (i.e. `~/.local/state/dagger/`). It's random when
newly initialized but re-used after that.

That solves this problem for non-nested clients. For nested clients, we
just set this to a random ID in each exec for now.
* It would also be possible to try to persist this in the nested exec,
  but it's not clear yet if that's worth the complication in that case,
  so keeping it simple for now.

Signed-off-by: Erik Sipsma <[email protected]>
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.

2 participants