Skip to content
Advertisement

Firebase functions using soap finishing with ECONNRESET “socket hang up”

I have a Firebase Function that was running for the last past two years that stopped working without any intervention on my part (no code change nor library update).

It is used to retreive data from an external service with soap, parse the data and send it back to a client which is an Android app and now it terminates with the error “socket hang up”.

Here’s a simplification of my firebase function that I use for my investigations :

import * as soap from "soap";
import * as constants from "constants";
import * as functions from "firebase-functions";
import * as admin from "firebase-admin";

export const getMakeManual = functions.region("europe-west1").https.onRequest(async (req, res) => {
      const url = functions.config().wsdl.path;
      const paths12 = functions.config().certificate.path;
      const password = functions.config().certificate.pwd
    
      const security = new soap.ClientSSLSecurityPFX(paths12, password);
      security.addOptions({
        strictSSL: false,
        rejectUnauthorized: false,
        secureOptions: constants.SSL_OP_NO_TLSv1_2,
        forever: false,
      });
    
      const getMakeArgs = {
        id: functions.config().id,
      };
    
      await soap.createClientAsync(url).then(async (client) => {
        client.setSecurity(security);
        await client.getMakeAsync(getMakeArgs).then((result : any) => {
          const rawResponseIndex = 1;
          console.log(result[rawResponseIndex]);
        }).catch((error : any) => {
          console.log(error);
        });
      });
    });

Here’s a snippet of my package.json :

  "engines": {
    "node": "16"
  },
  "main": "lib/index.js",
  "dependencies": {
    "fast-xml-parser": "^4.0.8",
    "firebase-admin": "^11.0.1",
    "firebase-functions": "^3.24.0",
    "googleapis": "^107.0.0",
    "soap": "^0.45.0"
  },

Here’s a snippet from the log:

Error: socket hang up
>      at connResetException (node:internal/errors:692:14)
>      at TLSSocket.socketOnEnd (node:_http_client:478:23)
>      at TLSSocket.emit (node:events:539:35)
>      at endReadableNT (node:internal/streams/readable:1345:12)
>      at processTicksAndRejections (node:internal/process/task_queues:83:21) {
>    code: 'ECONNRESET',

What I know so far:

  • The error seems to occur cause of the security options, if I remove the “client.setSecurity(security);” line the service answer with a “403 Forbidden” which is to be expected.
  • I have contacted the company that runs the service, they told me that they changed nothing.
  • I have contacted Firebase’s support for them nothing on their side.
  • I ran my function locally, checked with Wireshark if the communication wasn’t occuring and it’s the case. There are frame exchanges between my function and the service.

I have to admit that I’m a bit lost here. I’m thinking about using another saop library but I don’t expect to observe any change … Are there other tests that I can do ?

Advertisement

Answer

I found my issue.

The certificate was expired. The only tool to bring me this issue was curl, all the others gave me the ECONNRESET one.

then I used openssl to check the validity date and it was indeed expired.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement