# Remixjs, SSE

**URL:** <https://community.fly.io/t/remixjs-sse/12533>\
**Category:** Questions / Help\
**Tags:** login-only\
**Created:** [April 27, 2023, 8:30am UTC](https://community.fly.io/t/remixjs-sse/12533 "2023-04-27T08:30:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![debiip](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/debiip/32/11812_2.png) [@debiip](https://community.fly.io/u/debiip)\
**Post date:** [April 27, 2023, 8:30am UTC](https://community.fly.io/t/remixjs-sse/12533/1 "2023-04-27T08:30:22Z")

</div>

Hey everyone

## The problem

I can’t keep the server sent event connection alive for more than ~1 minute

I get this error in the browser console

```cli
GET https://domain.com/api/sse 502

```

### This is my resource route loader code

```ts
import { eventStream } from "remix-utils";
import { emitter } from "~/utils/notification/emitter.server";
import { Events, EventsType } from "~/utils/notification/events";
import { requireUser } from "~/utils/sessions/user.server";
import type { Notification } from "@prisma/client";

export async function loader({ request }: LoaderArgs) {
  const user = await requireUser(request);

  return eventStream(request.signal, function setup(send) {
    function handle(notification: Notification) {
      if (notification.userId !== user.id) return;

      send({ event: Events.newNotification, data: notification.id });
    }

    emitter.on(EventsType.notification, handle);

    return function clear() {
      emitter.off(EventsType.notification, handle);
    };
  });
}

```

the event works fine for about a minute then not

---

<div class="post-metadata">

**Author:** ![guillaume](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/guillaume/32/35150_2.png) [@guillaume](https://community.fly.io/u/guillaume)\
**Post date:** [April 27, 2023, 8:43am UTC](https://community.fly.io/t/remixjs-sse/12533/2 "2023-04-27T08:43:14Z")

</div>

Hey @debiip what you’re experiencing may be explained [here in our docs](https://fly.io/docs/reference/services/#idle-connection-timeouts). Our Fly Proxy ends idle connections after 1 minute. So you’ll need some reconnection logic.

---

<div class="post-metadata">

**Author:** ![debiip](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/debiip/32/11812_2.png) [@debiip](https://community.fly.io/u/debiip)\
**Post date:** [April 27, 2023, 8:50am UTC](https://community.fly.io/t/remixjs-sse/12533/3 "2023-04-27T08:50:52Z")

</div>

thanks for reply

is there an example on how to do that

---

<div class="post-metadata">

**Author:** ![guillaume](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/guillaume/32/35150_2.png) [@guillaume](https://community.fly.io/u/guillaume)\
**Post date:** [April 27, 2023, 9:01am UTC](https://community.fly.io/t/remixjs-sse/12533/4 "2023-04-27T09:01:32Z")

</div>

I’m not an expert on this topic, but our docs say that the `ioredis` Redis client handle those you can check out [their code](https://github.com/luin/ioredis/blob/main/lib/redis/event_handler.ts). It’s about your client detecting when the connection is closed and then reconnecting.

You could also have your server send regular “hearbeat” events to prevent the connection from being idle. But be sure to cleanup these properly when the clients leave your site or you’ll have memory leaks.

---

<div class="post-metadata">

**Author:** ![debiip](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/debiip/32/11812_2.png) [@debiip](https://community.fly.io/u/debiip)\
**Post date:** [April 27, 2023, 9:03am UTC](https://community.fly.io/t/remixjs-sse/12533/5 "2023-04-27T09:03:18Z")

</div>

thanks

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/fly1/original/3X/6/e/6e8955d00cb218e186ebbe3a6ab06fefdce15290.svg) [@system](https://community.fly.io/u/system)\
**Post date:** [May 4, 2023, 9:03am UTC](https://community.fly.io/t/remixjs-sse/12533/6 "2023-05-04T09:03:22Z")

</div>

Closed on May 4, 2023, 9:03am UTC

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