Title: Child_process fork - intermittent onread error
Tags: node.js;child-process
Question: I’m trying to create a caching server in node using child_process.fork.
The basic idea is that there’s a dispatching server that will spawn off forked “caching servers” based on the incoming URI. Once the caching servers are forked, the client sockets are sent to their appropriate forked caching server via the fork’s .send method.
cacheServers[this.key] = require('child_process').fork(‘CacheServer.js’,[this.key]);
... and then
cacheServers[subKey].send(“client”,clientSocket);
At times sending the client (and its socket) to a fork works fine, and at other times it throws an error:
TypeError: Cannot set property 'onread' of jamesli@example.com (child_process.js:134:21)
at ChildProcess.target.send (child_process.js:439:52)
at Server.server.Subscribe(/home/devuser/CachingServer/CachingServer.js:104:23)
at ChildProcess.<anonymous&gt; (/home/devuser/CachingServer/CachingServer.js:145:10)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at handleMessage (child_process.js:318:10)
at Pipe.channel.onread (child_process.js:345:11)
There seems to be no difference in the clients I’m sending to the fork.
Anyone out there have any clue at all?


Here is another answer: Looks like it has been fixed in v0.11.13 and v0.10.27?
Issue #5469
, Test
Comment for this answer: I'm still seeing the issue on v0.11.13, but it may be fine on other versions.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2014:00:06/19/14', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<node.js><child-process>', 'Title': 'Child_process fork - intermittent onread error', 'ViewCount': 199, 'id': 24318019, 'user_AboutMe': '<p>By day, I develop software solutions for companies, usually as a full stack developer (LAMP, MEAN.)</p>\n\n<p>By night, I play guitar semiprofessionally.</p>\n\n<p>For fun, I play music and play online games with friends.</p>\n\n<p>"Do good, have fun, make money" - I prefer working on projects that have all three qualities.</p>\n', 'user_AccountId': 3536205.0, 'user_DisplayName': 'user2954445', 'user_Reputation': 11.0, 'user_Views': 4.0, 'user_id': 2954445.0}}