Skip to content

Fix race condition in spec validation. Fixes #10. - #17

Closed
shykes wants to merge 3 commits into
mainfrom
fix-10
Closed

shykes wants to merge 3 commits into
mainfrom
fix-10

Conversation

@shykes

@shykes shykes commented Jan 12, 2021

Copy link
Copy Markdown
Contributor

There was a race condition which caused compute to fail randomly on environments with more than one component.

NOTE: concurrency is a work in progress. The current locking code is a placeholder pending deeper review. The (currently) intended place to implement cue runtime concurrency is in Compiler (our polyfill for cue.Runtime).

@aluzzardi

Copy link
Copy Markdown
Contributor

I don't think it's safe to remove locks around cue lookups. @samalba can chime in, he recently added more locks even though we're using a newer cue runtime.

@shykes

shykes commented Jan 12, 2021

Copy link
Copy Markdown
Contributor Author

Unfortunately if I keep the lock in Value.LookupPath, I get a deadlock when reproducing issue #10. Which makes sense because I think Spec.Validate calls Value.LookupPath.

I think our options are:

  1. Merge this PR, solve Multiple #dagger: compute calls does not seem to work? #10 but know we have other concurrency issues lurking which require fixing ASAP
  2. Close this PR, Multiple #dagger: compute calls does not seem to work? #10 requires another PR to be solved
  3. Modify this PR to keep lock in Value.LookupPath, race condition in Multiple #dagger: compute calls does not seem to work? #10 is replaced by a deadlock.

@samalba

samalba commented Jan 12, 2021

Copy link
Copy Markdown
Contributor

I don't think it's safe to remove locks around cue lookups. @samalba can chime in, he recently added more locks even though we're using a newer cue runtime.

I confirm all calls (including Lookup) need a lock to be thread safe. The symptom without lock on concurrent calls is usually a Cue config error.

@shykes

shykes commented Jan 12, 2021 •

Copy link
Copy Markdown
Contributor Author

Instead of protecting Spec.Validate we could protect the underlying unsafe cue operation... In this case would that be Fill ?

@shykes

shykes commented Jan 13, 2021

Copy link
Copy Markdown
Contributor Author

I have updated the PR to protect every cue call. The only exception is calls to cue.Iterator which I marked with a FIXME. I asked for more guidance on the Cue slack.

Unfortunately the race condition is still there. So I must have missed an operation which 1) is called by Spec.Validate 2) is not concurrency-safe 3) is not currently protected.

My only idea is Iterator. Besides that, I am out of ideas...

@shykes
shykes requested a review from aluzzardi January 13, 2021 20:19
@shykes

shykes commented Jan 13, 2021

Copy link
Copy Markdown
Contributor Author

I added protection for cue.Iterator. Race condition is still there. I am officially out of ideas...

@shykes

shykes commented Jan 13, 2021

Copy link
Copy Markdown
Contributor Author

For reference, cue concurrency is discussed here: cuelang/cue#613

@shykes

shykes commented Jan 13, 2021

Copy link
Copy Markdown
Contributor Author

Update: it looks like lock-protecting the cueflow calls in Env.Walk solves it! I will push an update to the PR.

@shykes

shykes commented Jan 13, 2021

Copy link
Copy Markdown
Contributor Author

cueflow fix pushed. I am unable to reproduce the race condition now. Please check if you get the same result?

Comment thread dagger/env.go Outdated

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.

No idea why, but by convention Mutex'es are handled without pointer (e.g. l := sync.Mutex{}). There must be a reason, I just don't know it.

@shykes

shykes commented Jan 14, 2021

Copy link
Copy Markdown
Contributor Author

I changed the cueflow protection to be more fine-grained (previous version actually serialized execution... doh!)

I am still getting race conditions. Without a better understanding of the nature of the underlying concurrency issues in the cue API, I cannot do much better than trying things at random.

Help needed...

aluzzardi added a commit that referenced this pull request Jan 20, 2021
@shykes

shykes commented Jan 22, 2021

Copy link
Copy Markdown
Contributor Author

This can be closed once #67 is merged.

@shykes shykes closed this Jan 25, 2021
@aluzzardi
aluzzardi deleted the fix-10 branch February 18, 2021 02:57
shykes referenced this pull request in shykes/dagger Apr 16, 2022
Updated the editingTemplate in Todo.js
vikram-dagger pushed a commit to vikram-dagger/dagger that referenced this pull request Aug 8, 2025
sipsma added a commit that referenced this pull request Oct 21, 2026
Pick up dagger/otel-go#25. When go test's -timeout fires, the test
binary prints the panic and goroutine stacks, test2json attributes that
output to whichever test reported last (possibly one that already
passed), and the package fails with no failure event for the tests left
running. otelgotest's quiet mode only flushed buffered output on a test
failure, so CI shards lost the timeout's dump unless diagnostics were
enabled. The runner now routes the timeout dump to the package and
flushes unfinished tests' output when their package fails. Quiet output
keeps the panic, the running-tests list and the first 64 KiB of the
stacks; the package span's logs keep the whole dump.

This also picks up dagger/otel-go#17, which makes otel-go's OTLP
conversion tolerate a missing resource and missing attribute and log
values. The engine's OTLP normalization stays, since a gauge with no
Gauge message still panics there; correct its comment, which said #17
was never merged.

Update dagql/CI.md, which described the old runner behavior.

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.

3 participants