#Rust fun cancellation

1 messages Β· Page 1 of 1 (latest)

runic kestrel
#

Hey Jed. Yes right now we share a reference to the Child process in the query. It should already be behind an arc and mutex if I recall correctly. Currently we just drop it once the arc has no more references. I'd actually assumed that it would kill the process on drop so that is definitely a bug/feature

  1. Yes we can add an explicit disconnect it would require a bit of custom logic but we can in rust even use struct generics to only make methods available on the client if it is active. Think a statemachine.
  2. Yes we can add that kind functionality our best bet currently is to do a blocking drop / cancel to make sure we do what you mention there. And if it hangs the process should either timeout (probably not a good idea as I am guessing clean up might take a bit) or hang until the sdk process is killed itself.

Overall i think ill have a peek and see how the other sdks does their thing. I haven't implemented a custom logging scheme either so right now rust is log by default unlike the goimpl

#

I believe async drop is a nightly only feature so I'll have to work around that if that is the approach we want. Shouldn't be a huge deal tho

minor rivet
#

yeah i think the explicit disconnect would be nice, but imo, the big one is that 1. we should make to cleanup the process for sure, and 2. cleanup the process with stdin.close() instead of SIGKILL

#

hm, the session process does get cleaned up actually it looks like

#

as in, it doesn't persist outside the cargo run

#

i wonder if there's some fun process group logic/etc that keeps this working?

#

oh hm i wonder if this works entirely as intended - when the parent exits, the stdin pipe is closed, so πŸŽ‰ the session exits neatly

#

but by not closing and waiting explicitly, this can be an issue if the child is pid 1 (or something weird like that)

#

ideally we wouldn't exit the parent until the child exited (like the other sdks)

runic kestrel
#

I guess this is as the name implies that the program spawns the process and as such is closed when the pid shuts down for the main program. I've never had issues with it, so I haven't looked into it. But if we want to do some best effort cleanup in the engine then I think we should do it more explicitly

minor rivet
#

Agreed πŸŽ‰ is there any chance you could take a look? I'm also happy to try and stumble my way through it, but my rust knowledge is definitely not very great

runic kestrel
#

I'll have a look. I'll shoot you a review / update whatever i end up finding out

steel haven
steel haven
runic kestrel
steel haven
runic kestrel
#

The wait automatically closes stdin of the process and waits for it to complete πŸ˜„

steel haven
#

ha neat

runic kestrel
#
Waits for the child to exit completely, returning the status that it exited with. This function will continue to have the same return value after it has been called at least once.

The stdin handle to the child process, if any, will be closed before waiting. This helps avoid deadlock: it ensures that the child does not block waiting for input from the parent, while the parent waits for the child to exit.

If the caller wishes to explicitly control when the child’s stdin handle is closed, they may .take() it before calling .wait():


#

Pretty cool I think πŸ˜„

steel haven
#

we just naturally chose such an ergonomic interface! πŸ˜›

runic kestrel
#

I've tested it and it does seem to cleanup the session before returning

#

All good. I needed a bit of a hack as it isn't possible to block a task in a drop. But hopefully that will be fine ones async drop is stable. It just went into nightly last week or so, so it will probably be a while

And didn't want to either change the ui, or implement a complicated solution

#

Interesting first time running rust generate from dagger call. xD

What could go wrong

runic kestrel
#

Okay I didn't manage to fully succeed. Somehow it seems that the process is being kept alive even tho it closes the stdin

Nvm figured it out. The hack I did doesn't work on a single threaded runtime

#

I'll continue tomorrow