# Unable to upload source maps due to backend closed connection erorr

**URL:** <https://discuss.elastic.co/t/unable-to-upload-source-maps-due-to-backend-closed-connection-erorr/344053>\
**Category:** APM\
**Tags:** elastic-stack-monitoring, nodejs\
**Created:** [September 28, 2023, 9:58am UTC](https://discuss.elastic.co/t/unable-to-upload-source-maps-due-to-backend-closed-connection-erorr/344053 "2023-09-28T09:58:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anandakumar](https://avatars.discourse-cdn.com/v4/letter/a/cc9497/32.png) [@Anandakumar](https://discuss.elastic.co/u/Anandakumar)\
**Post date:** [September 28, 2023, 9:58am UTC](https://discuss.elastic.co/t/unable-to-upload-source-maps-due-to-backend-closed-connection-erorr/344053/1 "2023-09-28T09:58:47Z")

</div>

Hi,

We have enabled APM RUM for our React app using @elastic/apm-rum package. And, we are trying to upload the source maps for the code base to APM, so that we can better debug our client application errors.

Following is the code from our pipeline, that pushes the source maps to APM.

```auto
const fs = require('fs');
const axios = require('axios');
const FormData = require('form-data');

const serviceVersion = '<our-service-version>'
const ELASTICSEARCH_DOMAIN = 'our-elastic-search-domain-name'
const ELASTICSEARCH_API_KEY = 'our-key'

const sourcemaps = fs.readdirSync('./public').filter((file) => file.endsWith('.map'));

const sourcemapRequests = sourcemaps.map((sourcemap) => {
  const bundledFilePath = `/${sourcemap.replace('.map', '')}`;
  const url = `${ELASTICSEARCH_DOMAIN}/api/apm/sourcemaps`;

  const data = new FormData();
  data.append('service_name', 'our-react-app');
  data.append('service_version', serviceVersion);
  data.append('bundle_filepath', bundledFilePath);
  data.append('sourcemap', fs.createReadStream(`./public/${sourcemap}`), {
    contentType: 'application/octet-stream',
  });

  const config = {
    headers: {
      'kbn-xsrf': 'true',
      Authorization: `ApiKey ${ELASTICSEARCH_API_KEY}`,
      ...data.getHeaders(),
    },
  };

  return axios
    .post(url, data, config)
    .then(() => {
      console.log('Uploaded', sourcemap);
    })
    .catch((error) => {
      console.log('Error uploading', sourcemap, '\nError:', error.response.data);
    });
});

Promise.all(sourcemapRequests)
  .then(() => console.log('Completed'))
  .catch((error) => console.error('An error occurred', error));

```

Only a very few source maps are uploaded and a majority of the source maps upload calls are failing with the following error:

```auto
Error uploading <filename>.js.map 
Error: { ok: false, message: 'backend closed connection' }

```

---

<div class="post-metadata">

**Author:** ![David\_Luna\_Bistuer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/david_luna_bistuer/32/122147_2.png) [@David\_Luna\_Bistuer](https://discuss.elastic.co/u/David_Luna_Bistuer)\
**Post date:** [September 28, 2023, 2:03pm UTC](https://discuss.elastic.co/t/unable-to-upload-source-maps-due-to-backend-closed-connection-erorr/344053/2 "2023-09-28T14:03:17Z")

</div>

Hi @Anandakumar,

recently we had a similar issue and was responded with some info links and samples of uploading sourcemaps. Please have a look

> [@How can I ensure that Elastic APM understands that an uploaded source map should be used for error monitoring?](https://discuss.elastic.co/t/how-can-i-ensure-that-elastic-apm-understands-that-an-uploaded-source-map-should-be-used-for-error-monitoring/342412/2):
>
> Hi @Casper_Aangeenbrug, Thanks for reaching out! I have a few questions and comments: What version of RUM are you using? (version 5.12 added [this fix](https://www.elastic.co/guide/en/apm/agent/rum-js/current/release-notes-5.x.html#_bug_fixes_3) for error capturing) What version of the elastic stack are you using? Are you using APM server standalone or APM integration? here is an [full-fledge example](https://discuss.elastic.co/t/uploading-sourcemaps-from-aix-webserver/303526/15) of how to make work sourcemaps for APM standalone with version 7.17, please take a look when you have time. Important: For higher versions the steps remain the same, the only d…

---

<div class="post-metadata">

**Author:** ![Alberto\_Delgado](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alberto_delgado/32/98488_2.png) [@Alberto\_Delgado](https://discuss.elastic.co/u/Alberto_Delgado)\
**Post date:** [September 28, 2023, 2:17pm UTC](https://discuss.elastic.co/t/unable-to-upload-source-maps-due-to-backend-closed-connection-erorr/344053/3 "2023-09-28T14:17:35Z")

</div>

Hi @Anandakumar,

I would like to add a little note, just in case:

Could you try uploading the `sourcemaps` one by one rather than all at once? I believe performing multiple requests to the same endpoint at once might be the reason for this issue.

Thanks,  
Alberto

---

<div class="post-metadata">

**Author:** ![Anandakumar](https://avatars.discourse-cdn.com/v4/letter/a/cc9497/32.png) [@Anandakumar](https://discuss.elastic.co/u/Anandakumar)\
**Post date:** [October 12, 2023, 12:55am UTC](https://discuss.elastic.co/t/unable-to-upload-source-maps-due-to-backend-closed-connection-erorr/344053/4 "2023-10-12T00:55:15Z")

</div>

Thanks for your response, Alberto.

Looks like it's only a very intermittent problem. Most times it's successful with parallel loads too.

---

<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:** [November 9, 2023, 12:56am UTC](https://discuss.elastic.co/t/unable-to-upload-source-maps-due-to-backend-closed-connection-erorr/344053/5 "2023-11-09T00:56:11Z")

</div>

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