From 2d98584de1292f86482da0ee1246c399b117f68f Mon Sep 17 00:00:00 2001 From: Sean T Allen Date: Wed, 23 May 2018 15:50:33 -0400 Subject: [PATCH] Update Backpressure.apply/release examples (#2708) 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] --- examples/under_pressure/main.pony | 4 ++++ packages/net/tcp_connection.pony | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/examples/under_pressure/main.pony b/examples/under_pressure/main.pony index 510dcf9210..0ff16c9452 100644 --- a/examples/under_pressure/main.pony +++ b/examples/under_pressure/main.pony @@ -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 diff --git a/packages/net/tcp_connection.pony b/packages/net/tcp_connection.pony index 84249fd5c1..87743274e4 100644 --- a/packages/net/tcp_connection.pony +++ b/packages/net/tcp_connection.pony @@ -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