bugaevc / pipe-channel

Channel implementation based on pipes
MIT License
2 stars 1 forks source link

Segfault between processes #2

Open crone123 opened 4 years ago

crone123 commented 4 years ago

Hello, I was looking for what my code segfault..... and it seem the recv() does bad things. I check out your code, and I see why it crash.

If you want you library to work between processes (like fork), you have to serialize the data. (using serde for example) You just send a block of ram through the pipe, so this works only with simple values (ex: int, float), and this will crash with more complex types, or heap allocated types like Vec, String, etc...

The only case it will really work, it's when you have only one single thread, and one process.

Too bad, I was really enjoyed to see someone who provide something similar to mpsc channel but across processes.

I note that you specify on you doc that it can crash with fork, but please, try to add something to prevent someone else compiling unsafe code as safe, or use the "unsafe" keyword to mark the attention of people who want to use your lib

Thank you, Valentin CRÔNE

bugaevc commented 4 years ago

I note that you specify on you doc that it can crash with fork, but please, try to add something to prevent someone else compiling unsafe code as safe, or use the "unsafe" keyword to mark the attention of people who want to use your lib

Yes, the docs explicitly call out using this between processes as unsafe. There's no unsafe keyword on the channel itself; because the channel is safe; whatever you're doing to get this working between processes (like calling fork()) is what should be marked unsafe.

Probably. Or maybe it shouldn't. At least opening a file for writing and writing some bytes into it is a safe operation, right? Yet you can easily cause a segfault by writing into your own memory as /proc/self/mem. Basically, there's no good way to protect you from using advanced OS mechanisms to crash yourself — we can only hope that in that case you know what you're doing even without explicit unsafe marks. Same goes for forking or using some other means to pass an fd to another process in case of pipe-channel.