-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support running in background #72
Conversation
3939a18
to
147d0bd
Compare
e308c2f
to
9b7b556
Compare
From this PR, I think |
707c137
to
56f2f9e
Compare
ASan is not happy with the tests. Any thoughts? |
131cb22
to
9817ad8
Compare
9817ad8
to
43703f5
Compare
43703f5
to
fdc740d
Compare
s3-file-connector/src/main.rs
Outdated
init_tracing_subscriber(); | ||
|
||
let (interrupt_tx, interrupt_rx) = crossbeam::channel::unbounded(); | ||
std::thread::spawn(move || await_interrupt(interrupt_tx)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a risk this happens too late? What if the mount completes in the child thread?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not likely to happen for success case due to network latency. Could be possible in some error cases that send the signal very soon. I'm not sure we should move this to before forking because I think the child process would copy the channel too. @jamesbornholt do you have any suggestions here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, yeah, this is unlikely but we should do it properly. That means creating a pipe (pipe2
) before the fork, writing a character into the write side of the pipe when the child wants to send its status (probably File::from_raw_fd
), and reading a character off the read side of the pipe in the parent to check the status (same). Doing timeouts will be more annoying this way, since you can't configure a timeout for file/pipe reads. Might need to spawn a thread to do it.
s3-file-connector/src/main.rs
Outdated
match session { | ||
Ok(_) => { | ||
let _ = nix::sys::signal::kill(parent_pid, Signal::SIGCONT); | ||
thread::park(); | ||
|
||
return Ok(()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is kind of subtle and we should be more explicit -- the session stays running because its lifetime is bound to the match statement, so doesn't drop until after the park
. Probably we should write Ok(_session)
and put a comment above the park
explaining this.
fdc740d
to
88d87ab
Compare
s3-file-connector/src/main.rs
Outdated
init_tracing_subscriber(); | ||
|
||
let (interrupt_tx, interrupt_rx) = crossbeam::channel::unbounded(); | ||
std::thread::spawn(move || await_interrupt(interrupt_tx)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, yeah, this is unlikely but we should do it properly. That means creating a pipe (pipe2
) before the fork, writing a character into the write side of the pipe when the child wants to send its status (probably File::from_raw_fd
), and reading a character off the read side of the pipe in the parent to check the status (same). Doing timeouts will be more annoying this way, since you can't configure a timeout for file/pipe reads. Might need to spawn a thread to do it.
88d87ab
to
d6dc79c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little uneasy on some of the multi-process logic, not that I understand the area well at this point.
Also, I expect the logic to change anyway with the pipe change.
00ac0ea
to
67cedc7
Compare
67cedc7
to
6e52bb5
Compare
// also `park()` does not guarantee to remain parked forever. so, we put it inside a loop. | ||
loop { | ||
thread::park(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need some kind of stopping condition.
When we receive SIGINT
, we should exit. Maybe another thread waits for SIGINT
, and sets an atomic bool?
Does this sound right, @jamesbornholt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the standard library already handle that. I have tested this by running kill -2 {pid}
which send SIGINT
to the running child process and it works just fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to figure something different out here, otherwise the process runs forever even if the user unmounts it. But we can do that as a followup, I think, because we'll probably have to make fuser changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that is existing problem, it keep running forever even for foreground process. It's just less visible when run in the background. Let's do it as a follow up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's open an issue and then we can resolve this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened #93.
6e52bb5
to
d465085
Compare
// also `park()` does not guarantee to remain parked forever. so, we put it inside a loop. | ||
loop { | ||
thread::park(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to figure something different out here, otherwise the process runs forever even if the user unmounts it. But we can do that as a followup, I think, because we'll probably have to make fuser changes.
s3-file-connector/src/main.rs
Outdated
// SAFETY: `read_fd` is a valid file descriptor. | ||
let mut f = unsafe { File::from_raw_fd(read_fd) }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe do this conversion outside the thread and right below closing the write_fd
, to make clearer the fate of the pipe (and give f
a better name)
This change allows the file connector to run in background and it will be running there by default. Users can change this behavior by passing in mount option `--foreground` or `-f` to run it in foreground instead. Signed-off-by: Monthon Klongklaew <[email protected]>
d465085
to
17b1af2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, pending new issue to follow up on failing to exit if unmounted.
After #72, our file connector will be running in background by default. This breaks the benchmark clean up process because we're now using the wrong pid to kill the process after unmount. Technically, running in background should not be a problem but because of #93 we will have to use `--foreground` flag until we have it fixed. Signed-off-by: Monthon Klongklaew <[email protected]>
* Fix benchmark script After #72, our file connector will be running in background by default. This breaks the benchmark clean up process because we're now using the wrong pid to kill the process after unmount. Technically, running in background should not be a problem but because of #93 we will have to use `--foreground` flag until we have it fixed. Signed-off-by: Monthon Klongklaew <[email protected]> * Update file system name in bench script Signed-off-by: Monthon Klongklaew <[email protected]> --------- Signed-off-by: Monthon Klongklaew <[email protected]>
This change allows the file connector to run in background and it will be running there by default. Users can change this behavior by passing in mount option
--foreground
or-f
to run it in foreground instead.I'm still figuring out how we can create some tests for this change. Any ideas are welcome. Another thing is that the logs are currently writing to the stdout directly even if the process is running in background. It's a bit annoying but I think that would be a part of PR that addresses #39.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.