-
Notifications
You must be signed in to change notification settings - Fork 366
Complete pending write operations before canceling io. #628
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -260,6 +260,18 @@ int | |
| syncio_close(struct w32_io* pio) | ||
| { | ||
| debug4("syncio_close - pio:%p", pio); | ||
|
|
||
| /* Flush descriptor.*/ | ||
| if (pio->write_details.pending) { | ||
| WaitForSingleObject(pio->write_overlapped.hEvent, INFINITE); | ||
|
|
||
| /* drain queued APCs */ | ||
| SleepEx(0, TRUE); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason why you added this call to SleepEx to this if statement block? |
||
| } | ||
|
|
||
| // This call is likely racy, there's no guarantee | ||
| // that a thread has begun IO operations when it's called. | ||
| // Why stop io operations when we're going to close it anyhow? | ||
| CancelIoEx(WINHANDLE(pio), NULL); | ||
|
||
|
|
||
| /* If io is pending, let worker threads exit. */ | ||
|
|
@@ -276,10 +288,10 @@ syncio_close(struct w32_io* pio) | |
|
|
||
| WaitForSingleObject(pio->read_overlapped.hEvent, INFINITE); | ||
| } | ||
| if (pio->write_details.pending) | ||
| WaitForSingleObject(pio->write_overlapped.hEvent, INFINITE); | ||
|
|
||
| /* drain queued APCs */ | ||
| SleepEx(0, TRUE); | ||
|
|
||
| /* TODO - fix this, closing Console handles is interfering with TTY/PTY rendering */ | ||
| if (FILETYPE(pio) != FILE_TYPE_CHAR) | ||
| CloseHandle(WINHANDLE(pio)); | ||
|
|
||
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.
Similar justification as:
openssh-portable/contrib/win32/win32compat/fileio.c
Lines 1089 to 1100 in cdee736
Feel free to modify this comment with any details that you think is relevant.
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 comment is similar to alternate path code for the file close operation, so I think it makes sense have it here as well, since we are using the same wait pattern.
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.
Yes, this was basically to perform the same logic before and after. My understanding/recollection is the sleep is actually needed to ensure that the queue actually gets drained.
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 just wondering if the queue needs to be drained immediately after the write operation terminates, or if we can just have one SleepEx call once both the read and write operation have terminated. I don't think it hurts to have it there, so I am good to merge as is. But I'm just wondering if it's needed.