Media Stream Node (ERR_STREAM_WRITE_AFTER_END)
I've been using the example code for a while as a base for some code I was writing. I haven't run the code for over a month on localhost on my machine, but when I tried running it yesterday I got an error. I redownloaded the sample code and ran it separately to try and isolate the issue, but I also got the same error (listed below).
> node server.js
Your app is listening on port 3000
Captured call CAe8bda7bf19bf88b6d3f171132fd877a1
Sending audio (44840 characters)
node:events:346
throw er; // Unhandled 'error' event
^
Error [ERR_STREAM_WRITE_AFTER_END]: write after end
at new NodeError (node:internal/errors:329:5)
at ClientHttp2Stream.Writable.write (node:internal/streams/writable:329:11)
at /Users/robert/Desktop/dialogflow-integration/node_modules/@grpc/grpc-js/build/src/call-stream.js:416:34
at processTicksAndRejections (node:internal/process/task_queues:94:5)
Emitted 'error' event on Http2CallStream instance at:
at emitErrorNT (node:internal/streams/destroy:188:8)
at emitErrorCloseNT (node:internal/streams/destroy:153:3)
at processTicksAndRejections (node:internal/process/task_queues:81:21) {
code: 'ERR_STREAM_WRITE_AFTER_END'
}
Here are the Ngrok logs when connecting:
2 0 0.03 0.01 1.94 2.61
HTTP Requests
-------------
GET /media 101 Switching Protocols
POST /twiml 200 OK
Things I've done to try and troubleshoot:
- Run the code on different computers (I have an intel Mac and also tried it on two separate PCs each running on different networks at different locations). The issue still occurs.
- I've tried downgrading Ngrok from version 2.3.38 to 2.3.35 (still an error)
- I tried using other localhost tunneling services like ultrahook and others
- I deployed the sample code to Digital Ocean's App platform and it worked there for some reason.
Based on the fact that it works on Digital Ocean but not on localhost, I wonder if there is something going on with the stream when it is being tunneled. Has anyone else been experiencing this issue recently? Any help would be greatly appreciated.
Thanks!
As a follow-up to this post, I looked on Digital Ocean App Platform and noticed that the containers are running on Node v12.22.1 by default. I installed nvm and set my global Node version to v12.22.1 on my local machine and the sample app works again. When I switched to Node v15.x.x the issue I mentioned earlier reappeared.
What changes would the sample app need to make it compatible with newer versions of Node?
I changed the "dialogflow" package to "@google-cloud/dialogflow" and it worked. Remember you need to change the dialogflow code as well in the dialogflow-utils.js file.
@satishp962 what code did you change exactly? i just made changed the import statement to use the new npm module name but now when i call i just hear silence. i know the /media event is getting triggered from logging but i no longer hear my dialogflow response being rendered as audio.
Hey, @gad2103 you can refer to these gist files. https://gist.github.com/satishp962/9219c3241f90e59122e131b95070f6ba
@satishp962 thanks for that. now its running. however what happens is the same issue i was seeing before the update. i call and i get the welcome event and hear the audio message. then i speak to trigger an intent and nothing happens. just silence until i hangup. it seems like my audio isn't being piped to dialogflow?
have you encountered this issue at all?
No. Do you see any errors in the logs?
No it doesn't show any errors it just shows this:
Captured call CAxxxxxxx
Sending audio (43932 characters)
then nothing happens.
Are you calling the actual number or testing from the Twilio console?
i'm calling the actual number
@gad2103 I had the same issue. Did you find the issue?
If I run with node version v12.22.1. It is working fine.
If I run with node version v12.22.1. It is working fine.
this works, thanks