Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Media Stream Node (ERR_STREAM_WRITE_AFTER_END) #94

Open
rhinck opened this issue Apr 18, 2021 · 12 comments
Open

Media Stream Node (ERR_STREAM_WRITE_AFTER_END) #94

rhinck opened this issue Apr 18, 2021 · 12 comments

Comments

@rhinck
Copy link

rhinck commented Apr 18, 2021

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:

  1. 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.
  2. I've tried downgrading Ngrok from version 2.3.38 to 2.3.35 (still an error)
  3. I tried using other localhost tunneling services like ultrahook and others
  4. 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!

@rhinck
Copy link
Author

rhinck commented Apr 20, 2021

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?

@satishp962
Copy link

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.

@gad2103
Copy link

gad2103 commented Apr 26, 2022

@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.

@satishp962
Copy link

Hey, @gad2103 you can refer to these gist files. https://gist.github.com/satishp962/9219c3241f90e59122e131b95070f6ba

@gad2103
Copy link

gad2103 commented Apr 26, 2022

@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?

@satishp962
Copy link

No. Do you see any errors in the logs?

@gad2103
Copy link

gad2103 commented Apr 26, 2022

No it doesn't show any errors it just shows this:

Captured call CAxxxxxxx
Sending audio (43932 characters)

then nothing happens.

@satishp962
Copy link

Are you calling the actual number or testing from the Twilio console?

@gad2103
Copy link

gad2103 commented Apr 26, 2022

i'm calling the actual number

@komirellipavan
Copy link

@gad2103 I had the same issue. Did you find the issue?

@komirellipavan
Copy link

If I run with node version v12.22.1. It is working fine.

@rodrigoGA
Copy link

If I run with node version v12.22.1. It is working fine.

this works, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants