Node.js socket _writableState是未定义的?

时间:2015-12-23 16:37:11

标签: javascript node.js sockets

我有一些代码应关闭套接字,但会导致错误:(使用NODE_DEBUG = net)

NET: 5482 onread undefined 32 7 39
NET: 5482 got data
NET: 5482 _read
ATL 0  // these are output from the program

3
ATL

net.js:425
  if (this._writableState.finished)
                         ^
TypeError: Cannot read property 'finished' of undefined
  at Socket.destroySoon (net.js:425:26)
  at Socket.<anonymous> (/home/crunch/js_relay_tools/atprox.js:45:4)
  at Socket.EventEmitter.emit (events.js:117:20)
  at Socket.<anonymous> (_stream_readable.js:746:14)
  at Socket.EventEmitter.emit (events.js:92:17)
  at emitReadable_ (_stream_readable.js:408:10)
  at emitReadable (_stream_readable.js:404:5)
  at readableAddChunk (_stream_readable.js:165:9)
  at Socket.Readable.push (_stream_readable.js:127:10)
  at TCP.onread (net.js:526:21)

这个套接字存储在一个数组中,但我不认为它应该有所作为。我已经尝试过Socket.end(我现在正在使用它)和Socket.destroySoon,但是都没有工作,并且有类似的错误(两者都处理未定义的套接字的可写状态)。

结束代码:

var sx = sa[parseInt(b[0])]; // get socket from array
var cf = sx==undefined?function (){sock.write("#E,no such socket")}:(sx.close || sx.end || function () {}); // get close/end function
cf(); // call close function
sa[parseInt(b[0])] = undefined; // clear array entry so socket cannot be closed again

这更令人感兴趣的是我在脚本中的另一个地方有类似的代码,它工作正常,使用相同的数组。我已经确认套接字实际上是打开的,能够发送和接收数据,但不能关闭。

TL; DR:Socket._writableState未定义,但我仍然可以读取和写入套接字,我无法关闭/结束它

这是一个错误,还是我搞砸了?

0 个答案:

没有答案