statsig-io / node-js-server-sdk

Statsig's SDK for server-side Node.js applications.
ISC License
20 stars 15 forks source link

serverless and socket tls disconnection #45

Closed shrynx closed 4 months ago

shrynx commented 4 months ago

we are using serverless framework and our logs are constantly bombarded with such logs below

FetchError: request to https://api.statsigcdn.com/v1/download_config_specs/secret-XXXXXXXXXXX.json?sinceTime=1717766609627 failed, reason: Client network socket disconnected before secure TLS connection was established\n at ClientRequest. (/node_modules/node-fetch/lib/index.js:1501:11)\n at ClientRequest.emit (node:events:529:35)\n at ClientRequest.emit (node:domain:489:12)\n at TLSSocket.socketErrorListener (node:_http_client:501:9)\n at TLSSocket.emit (node:events:517:28)\n at TLSSocket.emit (node:domain:489:12)\n at emitErrorNT (node:internal/streams/destroy:151:8)\n at emitErrorCloseNT (node:internal/streams/destroy:116:3)\n at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {\n type: 'system',\n errno: 'ECONNRESET',\n code: 'ECONNRESET'\n}\n

the setup code for serverless we have is

const serverlessHandler = serverless(app);

export const handler = async (event: object, context: object) => {
  await Statsig.initialize(
    process.env.STATSIG_SERVER_KEY || "",
    { environment: "production" }
  );
  return await serverlessHandler(event, context);
};
kenny-statsig commented 4 months ago

@shrynx The request to https://api.statsigcdn.com/v1/download_config_specs is necessary for any SDK functionality. Unless you are using a data adatper which is recommended for serverless environments. I'm not sure what your goal is but if what you really want to do is mute these logs, you can override the console.log via the logger option. But note that the SDK wont function properly unless this error is properly addressed.