tcp.write(): cast memoryview to 1byte itemsize
@@ -261,6 +261,12 @@ class TCP(Comm):
if each_frame_nbytes:
if stream._write_buffer is None:
raise StreamClosedError()
+
+ if isinstance(each_frame, memoryview):
+ # Make sure that len(data) == data.nbytes`
+ # See <https://github.com/tornadoweb/tornado/pull/2996>
+ each_frame = memoryview(each_frame).cast("B")
+
stream._write_buffer.append(each_frame)
stream._total_write_index += each_frame_nbytes
