# APM Server transport error: Error: write after end

**URL:** <https://discuss.elastic.co/t/apm-server-transport-error-error-write-after-end/165484>\
**Category:** APM\
**Created:** [January 23, 2019, 8:53pm UTC](https://discuss.elastic.co/t/apm-server-transport-error-error-write-after-end/165484 "2019-01-23T20:53:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmerefield](https://avatars.discourse-cdn.com/v4/letter/j/eada6e/32.png) [@jmerefield](https://discuss.elastic.co/u/jmerefield)\
**Post date:** [January 23, 2019, 8:53pm UTC](https://discuss.elastic.co/t/apm-server-transport-error-error-write-after-end/165484/1 "2019-01-23T20:53:55Z")

</div>

Using the sample code found at [https://www.elastic.co/guide/en/apm/agent/nodejs/current/lambda.html](https://www.elastic.co/guide/en/apm/agent/nodejs/current/lambda.html) I get an Ok response from the initial call but the error "APM Server transport error: Error: write after end" for subsequent calls, assuming this is due to the reuse of containers for 'warm' starts.  
Turning on the debug log on the agent this error occurs attempting to 'sending transaction %o'

Any ideas on how to fix this?

---

<div class="post-metadata">

**Author:** ![wa7son](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wa7son/32/21259_2.png) [@wa7son](https://discuss.elastic.co/u/wa7son)\
**Post date:** [January 24, 2019, 9:28am UTC](https://discuss.elastic.co/t/apm-server-transport-error-error-write-after-end/165484/2 "2019-01-24T09:28:57Z")

</div>

Hmm good question 🤔 I wonder if this is somehow related to our new intake API that was released in APM Server v6.5 - as this will try to keep the connection open between requests.

Would it be possible for you to install the previous major version of the Node.js agent (`^1.14.5`) and see if the problem goes away? That version used the old intake API which is still supported by all 6.x versions of the APM Server.

I'm not saying this is a permanent solution, but it would point us in the right direction 🙂

---

<div class="post-metadata">

**Author:** ![jmerefield](https://avatars.discourse-cdn.com/v4/letter/j/eada6e/32.png) [@jmerefield](https://discuss.elastic.co/u/jmerefield)\
**Post date:** [January 24, 2019, 9:32pm UTC](https://discuss.elastic.co/t/apm-server-transport-error-error-write-after-end/165484/3 "2019-01-24T21:32:36Z")

</div>

Thanks Thomas, I installed version 1.14.5 and the error went away. I can see the transactions appearing in the APM server log now.

---

<div class="post-metadata">

**Author:** ![wa7son](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wa7son/32/21259_2.png) [@wa7son](https://discuss.elastic.co/u/wa7son)\
**Post date:** [January 24, 2019, 10:06pm UTC](https://discuss.elastic.co/t/apm-server-transport-error-error-write-after-end/165484/4 "2019-01-24T22:06:02Z")

</div>

Good to hear. Thanks for trying it out.

I've created [an issue](https://github.com/elastic/apm-agent-nodejs/issues/827) so this can get fixed. I unfortunately don't know yet how complicated a fix will be, so it's hard to say how long it will take to fix it.

If you want to be using version 2.x of the agent in the meantime, you could try to set the [`apiRequestSize`](https://www.elastic.co/guide/en/apm/agent/nodejs/current/configuration.html#api-request-size) config option to a very low value to force it to close the HTTP request to the APM Server each time it transmitted a new event. Unless it's an issue with the underlying TCP socket, then this might be a temporary work around.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 14, 2019, 6:06pm UTC](https://discuss.elastic.co/t/apm-server-transport-error-error-write-after-end/165484/5 "2019-02-14T18:06:08Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
