Skip to content

Commit 98277d3

Browse files
committed
raise IOError when connection is closed before a write
1 parent 30e988f commit 98277d3

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/async/container/supervisor/connection.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,9 @@ def next_id
253253
#
254254
# @parameter message [Hash] The message to write.
255255
def write(**message)
256+
raise IOError, "Connection is closed!" unless @stream
256257
@stream&.write(JSON.dump(message) << "\n")
257-
@stream&.flush
258+
@stream&.flush # it is possible for @stream to become nil after the write call
258259
end
259260

260261
# Read a message from the connection stream.
@@ -327,9 +328,9 @@ def close
327328
@reader = nil
328329
end
329330

330-
if @stream
331-
@stream.close
331+
if stream = @stream
332332
@stream = nil
333+
stream.close
333334
end
334335

335336
if @calls

0 commit comments

Comments
 (0)