Server-Sent Events cycling between open and error

I am trying to make server-sent events work on my site above. On my local machine I can send and receive messages as expected. After deploying to Netlify, when I navigate to the page which has the react component that is using server-sent events, I notice it opens an eventSource connection but then errors out immediately after. What could be causing this connection to fail?

May 18, 12:29:29 AM: bf909a3d INFO inside stream.ts
May 18, 12:29:38 AM: bf909a3d ERROR Task timed out after 10.02 seconds
May 18, 12:29:38 AM: bf909a3d Duration: 10016.05 ms Memory Usage: 35 MB
May 18, 12:29:39 AM: INIT_START Runtime Version: nodejs:18.v28 Runtime Version ARN: arn:aws:lambda:us-east-2::runtime:b475b23763329123d9e6f79f51886d0e1054f727f5b90ec945fcb2a3ec09afdd
May 18, 12:29:42 AM: cd7067ee INFO inside stream.ts
May 18, 12:29:52 AM: cd7067ee ERROR Task timed out after 10.01 seconds
May 18, 12:29:52 AM: cd7067ee Duration: 10014.64 ms Memory Usage: 35 MB
May 18, 12:29:52 AM: INIT_START Runtime Version: nodejs:18.v28 Runtime Version ARN: arn:aws:lambda:us-east-2::runtime:b475b23763329123d9e6f79f51886d0e1054f727f5b90ec945fcb2a3ec09afdd
May 18, 12:29:55 AM: 83de8257 INFO inside stream.ts
May 18, 12:30:05 AM: 83de8257 ERROR Task timed out after 10.01 seconds
May 18, 12:30:05 AM: 83de8257 Duration: 10014.32 ms Memory Usage: 35 MB
May 18, 12:30:05 AM: INIT_START Runtime Version: nodejs:18.v28 Runtime Version ARN: arn:aws:lambda:us-east-2::runtime:b475b23763329123d9e6f79f51886d0e1054f727f5b90ec945fcb2a3ec09afdd
May 18, 12:30:08 AM: f69a16cf INFO inside stream.ts
May 18, 12:30:18 AM: f69a16cf ERROR Task timed out after 10.01 seconds
May 18, 12:30:18 AM: f69a16cf Duration: 10014.40 ms Memory Usage: 36 MB
May 18, 12:30:18 AM: INIT_START Runtime Version: nodejs:18.v28 Runtime Version ARN: arn:aws:lambda:us-east-2::runtime:b475b23763329123d9e6f79f51886d0e1054f727f5b90ec945fcb2a3ec09afdd
May 18, 12:30:21 AM: 30c1bbcd INFO inside stream.ts
May 18, 12:30:31 AM: 30c1bbcd ERROR Task timed out after 10.01 seconds
May 18, 12:30:31 AM: 30c1bbcd Duration: 10014.29 ms Memory Usage: 35 MB
May 18, 12:30:31 AM: INIT_START Runtime Version: nodejs:18.v28 Runtime Version ARN: arn:aws:lambda:us-east-2::runtime:b475b23763329123d9e6f79f51886d0e1054f727f5b90ec945fcb2a3ec09afdd
May 18, 12:30:35 AM: 1903b102 INFO inside stream.ts
May 18, 12:30:45 AM: 1903b102 ERROR Task timed out after 10.01 seconds
May 18, 12:30:45 AM: 1903b102 Duration: 10014.38 ms Memory Usage: 36 MB
May 18, 12:30:45 AM: INIT_START Runtime Version: nodejs:18.v28 Runtime Version ARN: arn:aws:lambda:us-east-2::runtime:b475b23763329123d9e6f79f51886d0e1054f727f5b90ec945fcb2a3ec09afdd
May 18, 12:30:48 AM: d9e5715d INFO inside stream.ts
May 18, 12:30:58 AM: d9e5715d ERROR Task timed out after 10.01 seconds
May 18, 12:30:58 AM: d9e5715d Duration: 10014.25 ms Memory Usage: 35 MB
May 18, 12:30:58 AM: INIT_START Runtime Version: nodejs:18.v28 Runtime Version ARN: arn:aws:lambda:us-east-2::runtime:b475b23763329123d9e6f79f51886d0e1054f727f5b90ec945fcb2a3ec09afdd
May 18, 12:31:01 AM: d6b54a9b INFO inside stream.ts
May 18, 12:31:11 AM: d6b54a9b ERROR Task timed out after 10.01 seconds
May 18, 12:31:11 AM: d6b54a9b Duration: 10014.86 ms Memory Usage: 35 MB
May 18, 12:31:11 AM: INIT_START Runtime Version: nodejs:18.v28 Runtime Version ARN: arn:aws:lambda:us-east-2::runtime:b475b23763329123d9e6f79f51886d0e1054f727f5b90ec945fcb2a3ec09afdd
May 18, 12:31:14 AM: ae4eece7 INFO inside stream.ts
May 18, 12:31:24 AM: ae4eece7 ERROR Task timed out after 10.01 seconds
May 18, 12:31:24 AM: ae4eece7 Duration: 10014.18 ms Memory Usage: 36 MB
May 18, 12:31:24 AM: INIT_START Runtime Version: nodejs:18.v28 Runtime Version ARN: arn:aws:lambda:us-east-2::runtime:b475b23763329123d9e6f79f51886d0e1054f727f5b90ec945fcb2a3ec09afdd
May 18, 12:31:27 AM: 5ed1f4a8 INFO inside stream.ts
May 18, 12:31:37 AM: 5ed1f4a8 ERROR Task timed out after 10.02 seconds
May 18, 12:31:37 AM: 5ed1f4a8 Duration: 10015.88 ms Memory Usage: 35 MB
May 18, 12:31:37 AM: INIT_START Runtime Version: nodejs:18.v28 Runtime Version ARN: arn:aws:lambda:us-east-2::runtime:b475b23763329123d9e6f79f51886d0e1054f727f5b90ec945fcb2a3ec09afdd
May 18, 12:31:40 AM: e07f3d05 INFO inside stream.ts
May 18, 12:31:50 AM: e07f3d05 ERROR Task timed out after 10.01 seconds
May 18, 12:31:50 AM: e07f3d05 Duration: 10014.46 ms Memory Usage: 35 MB
May 18, 12:31:50 AM: INIT_START Runtime Version: nodejs:18.v28 Runtime Version ARN: arn:aws:lambda:us-east-2::runtime:b475b23763329123d9e6f79f51886d0e1054f727f5b90ec945fcb2a3ec09afdd
May 18, 12:31:53 AM: a24d2447 INFO inside stream.ts
May 18, 12:32:03 AM: a24d2447 ERROR Task timed out after 10.01 seconds
May 18, 12:32:03 AM: a24d2447 Duration: 10014.36 ms Memory Usage: 36 MB
May 18, 12:32:03 AM: INIT_START Runtime Version: nodejs:18.v28 Runtime Version ARN: arn:aws:lambda:us-east-2::runtime:b475b23763329123d9e6f79f51886d0e1054f727f5b90ec945fcb2a3ec09afdd
May 18, 12:32:07 AM: ac14a6d2 INFO inside stream.ts
May 18, 12:32:17 AM: ac14a6d2 ERROR Task timed out after 10.01 seconds
May 18, 12:32:17 AM: ac14a6d2 Duration: 10014.33 ms Memory Usage: 35 MB
May 18, 12:32:17 AM: INIT_START Runtime Version: nodejs:18.v28 Runtime Version ARN: arn:aws:lambda:us-east-2::runtime:b475b23763329123d9e6f79f51886d0e1054f727f5b90ec945fcb2a3ec09afdd
May 18, 12:32:20 AM: a2cade46 INFO inside stream.ts
May 18, 12:32:30 AM: a2cade46 ERROR Task timed out after 10.01 seconds
May 18, 12:32:30 AM: a2cade46 Duration: 10014.97 ms Memory Usage: 34 MB
May 18, 12:32:30 AM: INIT_START Runtime Version: nodejs:18.v28 Runtime Version ARN: arn:aws:lambda:us-east-2::runtime:b475b23763329123d9e6f79f51886d0e1054f727f5b90ec945fcb2a3ec09afdd
May 18, 12:32:33 AM: f3a3da18 INFO inside stream.ts
May 18, 12:32:43 AM: f3a3da18 ERROR Task timed out after 10.02 seconds
May 18, 12:32:43 AM: f3a3da18 Duration: 10015.64 ms Memory Usage: 34 MB
May 18, 12:32:43 AM: INIT_START Runtime Version: nodejs:18.v28 Runtime Version ARN: arn:aws:lambda:us-east-2::runtime:b475b23763329123d9e6f79f51886d0e1054f727f5b90ec945fcb2a3ec09afdd
May 18, 12:32:46 AM: a0e452c3 INFO inside stream.ts
May 18, 12:32:56 AM: a0e452c3 ERROR Task timed out after 10.01 seconds
May 18, 12:32:56 AM: a0e452c3 Duration: 10014.12 ms Memory Usage: 36 MB
May 18, 12:32:56 AM: INIT_START Runtime Version: nodejs:18.v28 Runtime Version ARN: arn:aws:lambda:us-east-2::runtime:b475b23763329123d9e6f79f51886d0e1054f727f5b90ec945fcb2a3ec09afdd
May 18, 12:32:59 AM: fc73fe05 INFO inside stream.ts
May 18, 12:33:09 AM: fc73fe05 ERROR Task timed out after 10.01 seconds
May 18, 12:33:09 AM: fc73fe05 Duration: 10014.45 ms Memory Usage: 35 MB

You need Edge Functions for SSE: Server-Sent Events (SSE) | Edge Functions on Netlify (edge-functions-examples.netlify.app). Lambda Functions won’t work.

Ok thank you for the response. I was attempting to use edge functions, but couldn’t find a way to import files in from other parts of my codebase.

If I use an edge function to create an eventSource connection between the browser and server, how can I access my mongodb database logic from my edge function to grab some data and send it to the browser?

What error were you getting with importing?

As for Mongo, Edge Functions run on Deno. If a specific library doesn’t support that runtime, it won’t work.