Skip to content

Instantly share code, notes, and snippets.

@slfritchie
Created August 16, 2018 22:10
Show Gist options
  • Save slfritchie/558f44bcef5a29ad4ae9eaf208723bbc to your computer and use it in GitHub Desktop.
Save slfritchie/558f44bcef5a29ad4ae9eaf208723bbc to your computer and use it in GitHub Desktop.
Demonstrate Pony runtime shutdown hang by suspended TCP socket peer
use "net"
use "time"
actor Main
let _timers: Timers = Timers
new create(env: Env) =>
try
let sock = TCPConnection(env.root as AmbientAuth, recover Silly end, "localhost", "8888")
let delay: U64 = 5
@printf[I32]("Sleep for %d seconds...\n".cstring(), delay)
let t = Timer(recover Ticker(sock) end, delay*1_000_000_000)
_timers(consume t)
else
@printf[I32]("BUMMER!\n".cstring())
end
class Ticker is TimerNotify
let _sock: TCPConnection
new create(sock: TCPConnection) =>
_sock = sock
fun ref apply(timer: Timer, count: U64): Bool =>
@printf[I32]("Ticker, dispose socket\n".cstring())
_sock.dispose()
false
class Silly is TCPConnectionNotify
new create() =>
@printf[I32]("Silly create\n".cstring())
fun ref connecting(conn: TCPConnection ref, count: U32 val): None val =>
@printf[I32]("Silly connecting, count = %d\n".cstring(), count)
fun ref connect_failed(conn: TCPConnection ref) =>
@printf[I32]("Silly connect_failed\n".cstring())
fun ref connected(conn: TCPConnection ref) =>
@printf[I32]("Silly connected\n".cstring())
fun ref closed(conn: TCPConnection ref) =>
@printf[I32]("Silly closed\n".cstring())
fun ref received(conn: TCPConnection ref, data: Array[U8] iso, times: USize)
: Bool
=>
@printf[I32]("Silly received, data size = %d, times = %d\n".cstring(), data.size(), times)
false
fun ref sent(
conn: TCPConnection ref,
data: (String val | Array[U8 val] val))
: (String val | Array[U8 val] val)
=>
@printf[I32]("Silly sent, data size = %d\n".cstring(), data.size())
data
fun ref sentv(
conn: TCPConnection ref,
data: ByteSeqIter val)
: ByteSeqIter val
=>
@printf[I32]("Silly sentv, data size = ?lazy?\n".cstring())
data
fun ref throttled(conn: TCPConnection ref): None val =>
@printf[I32]("Silly throttled\n".cstring())
fun ref unthrottled(conn: TCPConnection ref): None val =>
@printf[I32]("Silly unthrottled\n".cstring())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment