stephen / nodetunes

AirTunes v2 Server implementation
215 stars 64 forks source link

Nodetunes crashes when second client tries to connect #49

Open sashahilton00 opened 7 years ago

sashahilton00 commented 7 years ago

Have noticed an issue whereby if a client is streaming to Airtunes, there is an intermittent bug whereby if a second client tries to connect, instead of displaying the 'Someone else is already using the speaker' message, it crashes nodetunes. The steps gone through to initialte the crash are as follows:

  1. Stream to nodetunes with one phone/laptop.
  2. Try streaming from a second client. Normally the first time one tries, you get the message about the speaker being in use, the second time it gives the in use popup twice, and the third time it crashes nodetunes, though I have equally found that this can occur on the first or second time a second client tries to connect at times.

The issue appears to be that on the time it crashes, the line in https://github.com/stephen/nodetunes/blob/master/lib/rtspmethods.js#L28 is trying to parse rtspServer.socket.address().address, which is undefined for whatever reason. This leads to ipaddr.js throwing an exception, and the entire app crashing. A trace is included below.

/Users/sashahilton/Documents/ds/node_modules/ipaddr.js/lib/ipaddr.js:494
      throw new Error("ipaddr: the address has neither IPv6 nor IPv4 format");
      ^

Error: ipaddr: the address has neither IPv6 nor IPv4 format
    at Object.ipaddr.parse (/Users/sashahilton/Documents/ds/node_modules/ipaddr.js/lib/ipaddr.js:494:13)
    at options (/Users/sashahilton/Documents/ds/node_modules/nodetunes/lib/rtspmethods.js:28:31)
    at RtspServer.<anonymous> (/Users/sashahilton/Documents/ds/node_modules/nodetunes/lib/rtsp.js:60:7)
    at emitTwo (events.js:106:13)
    at ServerParser.emit (events.js:192:7)
    at ServerParser._emitMessage (/Users/sashahilton/Documents/ds/node_modules/httplike/lib/server-parser.js:28:8)
    at ServerParser.Parser._write (/Users/sashahilton/Documents/ds/node_modules/httplike/lib/parser.js:91:14)
    at doWrite (_stream_writable.js:329:12)
    at writeOrBuffer (_stream_writable.js:315:5)
    at ServerParser.Writable.write (_stream_writable.js:241:11)
    at Socket.ondata (_stream_readable.js:555:20)

EDIT: This appears to be a rare bug in Node's underlying TCP server. Seen here: https://github.com/nodejs/node-v0.x-archive/issues/7566. Not sure what the work around is...

sashahilton00 commented 7 years ago

Ok, I've modified rtspmethods.js to catch the undefined address bug and return the loopback interface instead. Seems to work fine. Will submit a PR for it.