Dataloss using deserailise() or deserialize_from() with a TcpStream

This issue has been created since 2020-11-27.

Hi,

I've been playing with bincode for a message passing library I have been creating.

I have come upon a data loss bug in regards to how bincode deserialises data (It might not be just bincode, I am not well versed in SerDe).

With a TcpStream connection the buffer may have multiple messages in it if the receiver is slow to act upon receiving data.

if one is to run a read and then deserialise on a buffer with multiple messages in it. bincode will deseerialise the first message successfully and not return any errors.

Doing the same thing with deserailize_from(TcpStream) incurs the same problem -- it reads the entire buffer, deserialises the first message and discards the rest.

To me this is a correctness issue. As I am reliant on bincode to tell me the contents of my buffer. It should be telling me of an issue (in the case of deserialize()). Or at least how much is read. So I can make a decision on what to do with the rest.

In the case of deserialize_from() I would say that the function should be peeking at the data, finding out how much is part of a single message and only reading that amount from the buffer. The rest being left for the next call. This however will not work as peek is a TcpStream abstraction and not part of the Read trait. As such this should return an error with the buffer and allow for deserialize() to be used on the multiple messages.

Thanks.

ZoeyR wrote this answer on 2020-11-27

I'm not sure how deserialize_from is misbehaving in your case, can you construct a minimal reproduction?. deserialize_from shouldn't be reading any extra data in the read object.

thegatsbylofiexperience wrote this answer on 2020-11-27

Hiya,

I'm going to have to sheepishly say that deserialize_from is behaving with TcpStream. My 4am-sleep-deprived-mind that caused the issue. I missed a code path. I am very sorry for wasting your time.

With regards to the issue with deserialise maybe some documentation to push future newcomers towards serialize_from might help.

Happy to make a PR if you would like.

Please let me know.

Thank you for your time.

VictorKoenders wrote this answer on 2021-04-08

More documentation is always welcome, feel free to make that PR if you still have time

stale[bot] wrote this answer on 2021-06-13

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

More Details About Repo
Owner Name bincode-org
Repo Name bincode
Full Name bincode-org/bincode
Language Rust
Created Date 2014-09-17
Updated Date 2022-09-24
Star Count 1767
Watcher Count 27
Fork Count 221
Issue Count 21

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
Failure to install in macOS 12.0.1 with an M1 chip 2 2021-11-19 2022-08-29
Visual Prospecting makes it impossible to load a world after moving that world to a clean install of the same game version. 1 2022-09-07 2022-09-14
Dealing with multiple instance through depedency injection. 0 2022-02-26 2022-06-01
being able to use custom task or workflow name 1 2021-05-14 2022-09-25
Create an example in Next.js /examples folder 0 2021-09-05 2022-09-16
Incorporate ProtonDB 1 2021-05-13 2022-08-10
Impossible to download files, create folders and access files within Anbox 2 2021-07-09 2022-08-31
Update pegged dependencies but keep them pegged 3 2021-12-30 2022-09-23
[Bug]看视频会卡 1 2021-10-06 2022-01-18
Perfect Crime Saboteur ascendancy notable gives damage when it shouldn't. 1 2021-10-21 2022-09-24
PoB hangs after trying to open a build 1 2021-10-21 2022-09-29
docker completion commands end with * 1 2021-10-11 2022-07-12
Download Directory feature isn't working for a directory 3 2021-11-06 2022-01-01
'undefined' returned in tasksStore.$initItem 1 2021-03-22 2022-09-23
Fix factory making tests flakey 1 2021-07-04 2022-09-15
Heathrow "Royal Suite" Stands 1 2021-08-12 2022-09-28
Bad sunset/sunrise 2 2021-09-26 2022-01-17
Random Permission issue upon reading a file inside packaged exe 3 2021-11-18 2022-07-21
luminance-glutin lost CursorMode support 0 2020-04-15 2022-07-16
[8263] [MainThread] [ERROR] (uvicorn.error:56) - Application startup failed. Exiting. 9 2022-09-19 2022-09-22
Bug in function download_label 1 2022-09-24 2022-09-22
"Failed to save Label to MONAI Label Server" slicer plugin error 2 2022-09-20 2022-09-22
In: Contribute code to JuMP, talk about JuliaFormatter 0 2021-12-20 2022-09-13
PyGrid preparation 4 2020-07-06 2022-01-16
Restic forget fails with B2 and object locks despite --no-lock (and a crash in forget when remote lock fails) 10 2021-08-23 2022-09-27
`__file__` is sometimes missing the directory 3 2022-07-18 2022-09-22
[Bug] MacOS vmess-ws-tls V2ray可以通,clash配置始终不行 1 2022-01-17 2022-09-19
Add pagent support 2 2020-10-22 2022-01-13
feat: Implement GC proposal 0 2022-01-30 2022-09-23
Consider using readFileSync in GitHub target 0 2021-12-07 2022-09-15
Migrate setWeek function 0 2020-10-08 2022-09-29
write docs about customizing prettier config 0 2021-07-14 2022-07-24
Binding $parent[Type].Path works in App but not in XAML Preview 0 2022-01-10 2022-08-24
Selecting controls in designer is offset 2 2021-08-24 2022-08-24
www.techpowerup.com 1 2021-09-21 2021-12-30
🚨 Failure: General:Invalid arguments:volume 0 2021-11-13 2022-08-31
我在实际项目中的表单使用 searchSelect组件遇到的问题 1 2022-03-04 2022-09-06
Notifications are missing `isNew` and `read` fields 2 2021-09-30 2022-09-22
Not delete file but only delete from db 1 2021-11-16 2022-09-23
Size options for steps 2 2021-11-15 2022-07-13
xv6 operating system hangs when running on FPGA 10 2018-03-04 2022-09-27
pytorch ->onnx->MNN 推理结果完全错乱 2 2022-09-06 2022-09-23
int8 accuracy ResNet50 2 2022-06-03 2022-06-29
Custom backbones 2 2020-12-21 2022-01-10
Review custom styles for Kibana 7.9.0 2 2022-09-09 2022-09-25
[nextgen-editor] Relative links break inside editor 3 2022-01-06 2022-08-31
Encrypter contract has no getKey() method 9 2021-09-12 2022-09-29
Could not find a JavaScript runtime 2 2021-03-29 2022-08-30
Use Elasticsearch histogram type to store Prometheus histograms 2 2022-06-21 2022-09-29
"FileSystemException: Failed to set file modification time, path = '/home/zhl/ai_listener/.packages' (OS Error: Operation not permitted, errno = 1) 6 2022-03-20 2022-08-11