Repository navigation
Support signaling core.Start execs. - #2460
Conversation
There was a problem hiding this comment.
You could rewrite this as:
_#signals: {
SIGHUP: 1
SIGINT: 2
...
}
and then use:
#SendSignal: signal: or([for name, signal in _#signals { signal }])
There was a problem hiding this comment.
Nice, that's much cleaner! I also had to include a line that embedded _#signals on the top level of the file so outside callers could still say things like core.#SIGHUP, but that was easy too (thanks cue!)
b09e4bb to
cf2b2c6
Compare
TomChv
left a comment
There was a problem hiding this comment.
Left minor comments, that looks really good! I'll give it a try for my final review
There was a problem hiding this comment.
Nice, that's much cleaner! I also had to include a line that embedded _#signals on the top level of the file so outside callers could still say things like core.#SIGHUP, but that was easy too (thanks cue!)
Currently he will do core.SIGHUP, is it still ok for you?
There was a problem hiding this comment.
Ah yeah, I don't think making it a definition does anything since its just a concrete number.
There was a problem hiding this comment.
It is still an asynchronous execution, why did you remove that from log & error??
There was a problem hiding this comment.
Changed it because even though it is asynchronous, that's not the terminology we ended up using, so I thought that using async in the user-facing error message might be slightly confusing.
There was a problem hiding this comment.
Is it easy enough for the user to pick that container ID from the error message and find which action started it? Ideally this message would point to the action path of the #Start to avoid doing it manually.
There was a problem hiding this comment.
No it's not easy, good point. My next PR that's been pending this one adds logging support, which had to integrate the action path, so I think it will be a good place to address this.
TomChv
left a comment
There was a problem hiding this comment.
I just tried core.#Start but it didn't run the container asynchronuously.
Maybe I have misunderstood the usage but I expect that the container and the process do not stop until I stop dagger or send a signal SIGINT.
Here's my plan :
package main
import (
"dagger.io/dagger"
"dagger.io/dagger/core"
)
dagger.#Plan & {
actions: {
image: core.#Pull & {
source: "postgres:14.3-alpine"
}
test: {
start: core.#Start & {
input: image.output
args: ["docker-entrypoint.sh", "postgres"]
env: {
POSTGRES_PASSWORD: "password"
POSTGRES_USER: "foo"
POSTGRES_DB: "test"
image.config.env
}
}
}
}
}Here's a repro case with a docker command
docker run -p 5432:5432 -e POSTGRES_PASSWORD="password" -e POSTGRES_USER="foo" -e POSTGRES_DB="test" postgres:14.3-alpine docker-entrypoint.sh postgresDo I miss anything? That would be really cool to run a side database, specially for test purpose
|
@TomChv That's the expected behavior. Being asynchronous means that we don't wait for it to complete, the For the use case of running a database to be used by other tasks, what's expected is that you use There are test cases that verify all this behavior works as expected: https://github.com/dagger/dagger/blob/main/tests/tasks/exec/start_stop_exec.cue |
TomChv
left a comment
There was a problem hiding this comment.
This improvement is really amazing! I think we should write a piece of documentation about it because it's quite hard to understand how use it.
Feel free to open an issue to keep track of this ;)
PR LGTM on my side, I left questions but it is mergeable IMO
There was a problem hiding this comment.
This file become bigger and bigger after each improvement. If we continue like this, exec.go will be unmaintainable.
We should maybe work on a refactor of the file tree to make it more sustainable with that kind of improvement.
However, that should be done in a further PR
There was a problem hiding this comment.
Agree, I have more PRs pending this one, can update them to split things up here a bit more
There was a problem hiding this comment.
Also, on the cue side, maybe group the async stuff in a separate async.cue.
There was a problem hiding this comment.
Why not just return nil since the value is unused after that? or v?
There was a problem hiding this comment.
I think I tried returning just nil but got a nil pointer exception when the caller of this method tried to unify it with the original value. I guess you could have v unify with itself too but not sure there's much difference between that and returning a new empty value here.
There was a problem hiding this comment.
Okay, that's strange but it's ok to just return a new value then, thank you!
There was a problem hiding this comment.
Not strange, it's what I'd do. You can see it in Nop and ClientFilesystemWrite for example.
You need to return a value and it's wasteful to re-fill the "input" value. Tasks only return new values.
Thanks Tom! The remaining issues, including creating all the docs, are tracked here: #2398 Overall, the goal of these tasks in |
There was a problem hiding this comment.
Is it easy enough for the user to pick that container ID from the error message and find which action started it? Ideally this message would point to the action path of the #Start to avoid doing it manually.
There was a problem hiding this comment.
I'd just stop.exit & core.SIGKILL.
There was a problem hiding this comment.
I don't define core.SIGKILL (mention why in my other comment), but in retrospect my comment here is confusing because it's not that SIGKILL is literally equal to 137, it's that 137 is the exit code you get when a process is sigkilled (128+9). I'll clarify this comment.
There was a problem hiding this comment.
Ah yes, got confused there 🙂
There was a problem hiding this comment.
Maybe filter out SIGKILL if it's not supported?
| signal: or([ for name, signal in _signals {signal}]) | |
| signal: or([for _, signal in _signals if signal != _signals.SIGKILL { signal }]) |
There was a problem hiding this comment.
I actually just skipped even defining _signals.SIGKILL. The issue with it is that BuildKit sends signals to the process by sending them to runc, which is expected to forward the signal, but SIGKILL can't be caught+forwarded so it just results in runc dying and the underlying process getting orphaned. So it felt safer to just skip defining it at all.
There was a problem hiding this comment.
Ah got it. Sorry I didn't notice it wasn't in the list.
This adds a new core.SendSignal task that enables arbitrary signals to be sent to an async Start exec. It also adds related support to core.Stop for specifying a timeout to wait for the exec to exit on its own before sending SIGKILL. The main goal here is to support ending Start execs gracefully instead of being forced to always just SIGKILL them as part of core.Stop. It should be useful in general for any other use cases that call for signals to be sent to these execs (i.e. SIGWINCH for future tty support). Among other things, this is needed to support running Jaeger via core.Start (without a graceful stop, its data gets corrupted). Signed-off-by: Erik Sipsma <[email protected]>
This adds a new core.SendSignal task that enables arbitrary signals to
be sent to an async Start exec. It also adds related support to
core.Stop for specifying a timeout to wait for the exec to exit on its
own before sending SIGKILL.
The main goal here is to support ending Start execs gracefully instead
of being forced to always just SIGKILL them as part of core.Stop. It
should be useful in general for any other use cases that call for
signals to be sent to these execs (i.e. SIGWINCH for future tty
support).
Among other things, this is needed to support running Jaeger via
core.Start (without a graceful stop, its data gets corrupted).
Signed-off-by: Erik Sipsma [email protected]