Skip to content

Conversation

@SvenW
Copy link
Contributor

@SvenW SvenW commented Nov 27, 2025

This adds heartbeating for SSE subscriptions. With the new zio-http version these heartbeats are now sent as SSE comments (ignored by the client but keeps the connection up) making sure we don't close the connection if no messages are passed within the default timeouts

@SvenW SvenW marked this pull request as draft November 27, 2025 07:32
@SvenW SvenW force-pushed the fix/sse-heartbeats branch from 9071180 to 8406000 Compare November 28, 2025 06:48
@SvenW SvenW marked this pull request as ready for review November 28, 2025 06:48
@SvenW SvenW changed the title Fix/sse heartbeats Heartbeating for SSE based subscriptions Nov 28, 2025
@SvenW SvenW force-pushed the fix/sse-heartbeats branch from 1706163 to 0571d0a Compare December 1, 2025 09:25
@ghostdogpr
Copy link
Owner

The next release is likely to be 3.0.0 so could you target the series/3.x branch instead?

@SvenW SvenW force-pushed the fix/sse-heartbeats branch from 0571d0a to 5600211 Compare December 2, 2025 07:17
@SvenW SvenW changed the base branch from series/2.x to series/3.x December 2, 2025 07:17
@SvenW
Copy link
Contributor Author

SvenW commented Dec 2, 2025

The next release is likely to be 3.0.0 so could you target the series/3.x branch instead?

Of course. Do you already have a planned roadmap for the 3.0.0 release as well?

@ghostdogpr
Copy link
Owner

I'm just waiting for a new RC of sbt 2 because of #2771 (comment) and it should be good to release

Copy link
Collaborator

@kyri-petrou kyri-petrou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Some minor comments below, although:

  1. Is it possible to add a test for this or is it too difficult?
  2. Can we document this new functionality? Both in the scaladoc of the config and the page

}

object SseConfig {
def default: SseConfig = SseConfig(Some(10.seconds))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure whether enabling them by default is the correct approach. I think it's better for users to explicitly enable them?

}
case _ => ZStream.succeed(resp)
}).map(v => toSse(v.toResponseValue)) ++ ZStream.succeed(done)
}).map(v => toSse(v.toResponseValue)).mergeHaltLeft(heartbeater.getOrElse(ZStream.empty)) ++ ZStream.succeed(done)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid the merging if the heartbeater is None?

@SvenW
Copy link
Contributor Author

SvenW commented Dec 2, 2025

Thanks! Some minor comments below, although:

  1. Is it possible to add a test for this or is it too difficult?

Noticed that the TextEventStream test was flaky so didn't look into that yet, but might be worth it?

  1. Can we document this new functionality? Both in the scaladoc of the config and the page

Added some docs now regarding the configuration at least

@SvenW SvenW requested a review from kyri-petrou December 2, 2025 13:59
@kyri-petrou
Copy link
Collaborator

Noticed that the #2685 so didn't look into that yet, but might be worth it?

@SvenW I see. I think it's still worth adding a test. I imagine it won't be straightforward to write a test for this, so it'd be good to have one in place. If it turns out to be flaky as well we can ignore it until the underlying bug is resolved

@SvenW
Copy link
Contributor Author

SvenW commented Dec 8, 2025

Noticed that the #2685 so didn't look into that yet, but might be worth it?

@SvenW I see. I think it's still worth adding a test. I imagine it won't be straightforward to write a test for this, so it'd be good to have one in place. If it turns out to be flaky as well we can ignore it until the underlying bug is resolved

Agreed. I've added a test now but I realized that sttp doesn't support SSE comments fully either so ServerSentEvent will just be an empty event using that client in the tests. Not sure how we should handle that in this PR though. I'll try to dig around to understand why that's the case in sttp. Looks like it's been brought up at least softwaremill/sttp-model#379

@SvenW SvenW force-pushed the fix/sse-heartbeats branch from 7309689 to f2453f9 Compare December 8, 2025 09:36
@SvenW
Copy link
Contributor Author

SvenW commented Dec 15, 2025

What do you say @kyri-petrou? Do you want me to change anything else? Sorry for the ping btw

Copy link
Collaborator

@kyri-petrou kyri-petrou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, LGTM 🎉

@kyri-petrou
Copy link
Collaborator

@ghostdogpr happy to merge if you're OK with it as well

@ghostdogpr
Copy link
Owner

Let's go, thanks!

@ghostdogpr ghostdogpr merged commit 8bdb1d6 into ghostdogpr:series/3.x Dec 20, 2025
13 checks passed
@SvenW SvenW deleted the fix/sse-heartbeats branch January 9, 2026 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants