Skip to content

Commit 8bf44cc

Browse files
committed
a couple of safeguards
1 parent 4d1d6d8 commit 8bf44cc

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

ws4py/websocket.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ def send(self, payload, binary=False):
237237
238238
If ``binary`` is set, handles the payload as a binary message.
239239
"""
240+
if self.terminated:
241+
raise RuntimeError("Cannot send on a terminated websocket")
242+
240243
message_sender = self.stream.binary_message if binary else self.stream.text_message
241244

242245
if isinstance(payload, basestring) or isinstance(payload, bytearray):
@@ -271,6 +274,10 @@ def once(self):
271274
whatever size must be read from the connection since
272275
it knows the frame payload length.
273276
"""
277+
if self.terminated:
278+
logger.debug("WebSocket is already terminated")
279+
return False
280+
274281
s = self.stream
275282
sock = self.sock
276283
process = self.process

0 commit comments

Comments
 (0)