Skip to content

Commit

Permalink
Update Backpressure.apply/release examples (#2708)
Browse files Browse the repository at this point in the history
The examples given for how to use manually applied backpressure could lead
to deadlocking as it would be possible to dispose of the TCPConnection
or close it while backpressure had been applied and then not release it.

[skip ci]
  • Loading branch information
SeanTAllen authored and jemc committed May 23, 2018
1 parent a942b3c commit 2d98584
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions examples/under_pressure/main.pony
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ class SlowDown is TCPConnectionNotify
_out.print("Releasing backpressure!")
Backpressure.release(_auth)

fun ref closed(connection: TCPConnection ref) =>
_out.print("Releasing backpressure if applied!")
Backpressure.release(_auth)

fun ref connect_failed(conn: TCPConnection ref) =>
@printf[I32]("connect_failed\n".cstring())
None
Expand Down
6 changes: 6 additions & 0 deletions packages/net/tcp_connection.pony
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ actor TCPConnection
_out.print("Releasing backpressure!")
Backpressure.release(_auth)
fun ref closed(connection: TCPConnection ref) =>
// if backpressure has been applied, make sure we release
// when shutting down
_out.print("Releasing backpressure if applied!")
Backpressure.release(_auth)
fun ref connect_failed(conn: TCPConnection ref) =>
None
Expand Down

0 comments on commit 2d98584

Please sign in to comment.