rialto-php / rialto

Manage Node resources with PHP
MIT License
170 stars 76 forks source link

JSON instruction parsing on node process fails for large instructions #39

Open tpetry opened 2 years ago

tpetry commented 2 years ago

In my first tests everything was working correctly and rialto seemed like a nice solution. But after implementing everything, I encountered a strange bug which took a long to debug: Sending large instructions (10KB or 100KB) fails with the nodejs part throwing an error because of malformed JSON instructions. With small instructions, everything is working correctly.

I was able to pin-down the exact issue: When sending results from nodejs to php a chunked protocol is used. But it is not used when sending data from php to nodejs. The nodejs logic expects the instruction to be read in one single receive statement: https://github.com/rialto-php/rialto/blob/1e994b830e7a04e8440d78687c002c639a4c0a36/src/node-process/Connection.js#L46-L50

But with large instructions like sending large html documents this is not possible, there will be packet fragmentation. Chunking needs to be done on both ways.

lacieri commented 2 years ago

This is a duplicate of #87