Skip to content

Comments

windows: Finish pending writes when a socket is dropped#444

Closed
alexcrichton wants to merge 4 commits intotokio-rs:masterfrom
alexcrichton:write-then-drop
Closed

windows: Finish pending writes when a socket is dropped#444
alexcrichton wants to merge 4 commits intotokio-rs:masterfrom
alexcrichton:write-then-drop

Conversation

@alexcrichton
Copy link
Contributor

On Unix the kernel will do this for us, but on Windows we need to do it ourselves. Previously we would forcibly close a socket whenever a socket was dropped on Windows. This would leave around its associated Arc (for completion events), but it would cancel all I/O in flight.

Now we instead allow writes to finish (we don't cancel them), and we just cancel any reads that are in flight. This should ensure that we actually get around to closing the socket in a timely fashion (not blocked on a read that'll never come) but we'll still ensure that all the data we said we wrote actually gets written.

Closes #423

cc @seanmonstar

That way as soon as the I/O object is dropped we'll stop receiving readiness
notifications for it (as the handle has gone away).
No need to get synchronized access to this, it never changes.
To preserve the same semantics with Unix, when a `TcpStream` or `UdpSocket` is
dropped, we wait to actually close the socket itself until any pending write has
finished. To ensure that the socket closing is scheduled quickly, we do cancel
any pending reads, however.

Closes tokio-rs#423
Now that we never close a socket early, there's no need to have any interior
mutability. The socket provided is always valid and it can just live directly in
the Arc.
@seanmonstar
Copy link
Member

\o/

I can test later if you'd like

@carllerche
Copy link
Member

Thanks. Merged into dev

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.

Windows aborts TcpStreams on close

3 participants