nimbleape/asterisk-dialogflow-rtp-audioserver

cancel the timeouts for sending back audio if theres a hangup

danjenkins opened this issue · 3 comments

Stop trying to send media if a hangup mqtt message comes through

[1584132122790] INFO  (Dialogflow-AudioServer/11547 on ip-172-XXX-XXX-244): Destroying DialogFlow stream
    id: "1584132119.60"
events.js:288
      throw er; // Unhandled 'error' event
      ^

Error [ERR_STREAM_WRITE_AFTER_END]: write after end
    at writeAfterEnd (_stream_writable.js:264:14)
    at PassThrough.Writable.write (_stream_writable.js:313:5)
    at Timeout._onTimeout (/var/lib/asterisk/agi-bin/asterisk-dialogflow/asterisk-dialogflow-rtp-audioserver/lib/DialogFlowConnector.js:168:46)
    at listOnTimeout (internal/timers.js:549:17)
    at processTimers (internal/timers.js:492:7)
Emitted 'error' event on PassThrough instance at:
    at errorOrDestroy (internal/streams/destroy.js:108:12)
    at writeAfterEnd (_stream_writable.js:266:3)
    at PassThrough.Writable.write (_stream_writable.js:313:5)
    [... lines matching original stack trace ...]
    at processTimers (internal/timers.js:492:7) {
  code: 'ERR_STREAM_WRITE_AFTER_END'
}

Hi Dan,
To work around this issue i use a try catch

try {
    this._asteriskAudioStream.outWStream.write(packet.serialize());
} catch (error) {
    this.log.error(error);
}

This is just a work around the issue.

I also tried to to enclose the full for loop in a setTimeout var and clear that at the close event.
But for some reason not clear yet the error is still thrown. I am not sure if the loop is running seperatly and we can clear it this way. Otherwise i think we have to make a sure each time the Outstream is writen the bridge is checked if the stream is still open.

@JorgMuskens I just pushed a commit which should fix this. I thought about checking if the stream was writable every time but I'd still have to deal with cancelling all future timeouts so decided a try catch was better and would at least handle other bad situations instead of crashing out. let me know if it works for you

I have the issue back. It throws the error when you keep quite and say nothing.
This happend to me when my speech was not recognized and looks like dialogflow then closes connecting which throws the error. Note that i am using singleUtterance: true to get the speech going in Dialogflow. I see you are using false but on my end Dialogflow doesn't reply back to me then.