While implementing server sent events (SSE) requests I've come across a problem. The streams quickly become stale. The client continues to request data, but the server will only respond with "hello".

This might happen after just 1 batch of data, or it may happen after several batches.

Once it gets into the no-data mode, no further events are received.

Here's debug from a sample run:

Streaming https://horizon.stellar.org/transactions?cursor=now

=== Reconnection ===
Request headers:
* Accept: text/event-stream

Response headers: 
* Access-Control-Allow-Origin: *
* Cache-Control: no-cache
* Date: Mon, 03 Sep 2018 06:21:57 GMT
* Vary: Origin
* X-Ratelimit-Limit: 17200
* X-Ratelimit-Remaining: 16820
* X-Ratelimit-Reset: 2559
* Connection: keep-alive

Content:
eventType: Some(open), id:None, retry:Some(1000), data:"hello"
eventType: None, id:Some(85020647150878720), retry:None, data:Txn 085a68b39a5e6b55e9e7952e714c73b21b5e6625ee03213bd63a42927f4a2ac5
eventType: None, id:Some(85020647150882816), retry:None, data:Txn d6d6ba453872425498b262cae1e1b85caa1ec66a1a717822fc04abd34fc89128
eventType: None, id:Some(85020647150886912), retry:None, data:Txn 9644f2fce64854fef1a1c01e856231317c532c6a131c0b96cb0c064e0bf7e6b9
eventType: None, id:Some(85020647150891008), retry:None, data:Txn b5dbb06f5f72f1f9bf4d895235855fe2397f88d45e13bde5c8218f3f80bdf379
eventType: None, id:Some(85020647150895104), retry:None, data:Txn 735865f6a78fc13c6d9a8f7a7d93d01b881b0296db0cf2e5914930bd7db1ce78
eventType: None, id:Some(85020647150899200), retry:None, data:Txn b289c8c381d09dd9a58356e4fd8e92ebc1764dfdf60a472a4bb9703d64300a15
eventType: None, id:Some(85020647150903296), retry:None, data:Txn 152a1fa5e0e4dcd9ae918045e6c5eea1cafe574f309701005533df9775a94907
eventType: None, id:Some(85020647150907392), retry:None, data:Txn 276d288ec0a32ad014dbd4bf338f426c1ec6c62a040cb1f25dcb97b08c027ed5
eventType: None, id:Some(85020647150911488), retry:None, data:Txn b825ca36015ad9fd5fc1c39c4c7c775721efd3dbc4972c8c15b40468d85131c3
eventType: None, id:Some(85020647150915584), retry:None, data:Txn c16d4aef6a01312b2be29a4318e8c48b8c98a8649ed7da9608f87095f5d5a39e

=== Reconnection ===
Request headers:
* Accept: text/event-stream
* Last-Event-ID: 85020647150915584

Response headers: 
* Access-Control-Allow-Origin: *
* Cache-Control: no-cache
* Date: Mon, 03 Sep 2018 06:21:57 GMT
* Vary: Origin
* X-Ratelimit-Limit: 17200
* X-Ratelimit-Remaining: 16819
* X-Ratelimit-Reset: 2559
* Connection: keep-alive

Content:
eventType: Some(open), id:None, retry:Some(1000), data:"hello"
eventType: None, id:Some(85020647150919680), retry:None, data:Txn 9149a855576c2a225bb9801fe9cda8359ff920898c73e1a846c7d93ea8f014ba
eventType: None, id:Some(85020647150923776), retry:None, data:Txn a060ef3263f5bb7d5042d30b50213a96b7c3fb9daca61db2f73277b32c5ffa66
eventType: None, id:Some(85020651445821440), retry:None, data:Txn adaaf881bedbcad03c42ff44537b7e36f63012686267c55b31793870c9b93049
eventType: None, id:Some(85020651445825536), retry:None, data:Txn a804fa772108a67bbda4455084041f2c68396eaed59eb5588300b490ac4c3b40
eventType: None, id:Some(85020651445829632), retry:None, data:Txn 5b11469c1bf4e6ba4f3bd8d746bd214ef1514355f7d3268b744c688177b8d2b1
eventType: None, id:Some(85020651445833728), retry:None, data:Txn 68cf8bcbd4b18dfa7413c9579f115ebae07fc9c4d4f6990979e286419b2084d8
eventType: None, id:Some(85020651445837824), retry:None, data:Txn 6f73262d029a4fdba42a14c1a60f5110e6e66e5f82b911fce84607a204b96a7e

=== Reconnection ===
Request headers:
* Accept: text/event-stream
* Last-Event-ID: 85020651445837824

Response headers: 
* Access-Control-Allow-Origin: *
* Cache-Control: no-cache
* Date: Mon, 03 Sep 2018 06:22:02 GMT
* Vary: Origin
* X-Ratelimit-Limit: 17200
* X-Ratelimit-Remaining: 16818
* X-Ratelimit-Reset: 2555
* Connection: keep-alive

Content:
eventType: Some(open), id:None, retry:Some(1000), data:"hello"

=== Reconnection ===
Request headers:
* Accept: text/event-stream
* Last-Event-ID: 85020651445837824

Response headers: 
* Access-Control-Allow-Origin: *
* Cache-Control: no-cache
* Date: Mon, 03 Sep 2018 06:22:02 GMT
* Vary: Origin
* X-Ratelimit-Limit: 17200
* X-Ratelimit-Remaining: 16766
* X-Ratelimit-Reset: 2549
* Connection: keep-alive

Content:
eventType: Some(open), id:None, retry:Some(1000), data:"hello"

And so it repeats forever, presenting the open "hello" message with each request.

If I run same query via the lab at the same time I can see there are events that should be streamed. They are just not being provided to my client. Is there something wrong with the request?

More info

If I make a new request starting from the last event id, it also returns nothing.

Streaming https://horizon.stellar.org/transactions?cursor=85020651445837824

=== Reconnection ===
Request headers:
* Accept: text/event-stream
* Last-Event-ID: 85020651445837824

Response headers: 
* Access-Control-Allow-Origin: *
* Cache-Control: no-cache
* Date: Mon, 03 Sep 2018 06:29:45 GMT
* Vary: Origin
* X-Ratelimit-Limit: 17200
* X-Ratelimit-Remaining: 17195
* X-Ratelimit-Reset: 3502
* Connection: keep-alive

Content:
eventType: Some(open), id:None, retry:Some(1000), data:"hello"

This is despite the fact that there are records from that id onwards.

This tells me that there's probably a problem with the request itself, and not the SSE library I'm using.

A successful request from the lab is:

Accept: text/event-stream
Accept-Encoding: gzip, deflate, br
Accept-Language: en-AU,en-GB;q=0.9,en-US;q=0.8,en;q=0.7
Cache-Control: no-cache
Connection: keep-alive
DNT: 1
Host: horizon.stellar.org
Last-Event-ID: 85020651445882880
Origin: https://www.stellar.org
Pragma: no-cache
Referer: https://www.stellar.org/laboratory/
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36

Whereas my apps request headers are simply:

Accept: text/event-stream
Last-Event-ID: 85020651445837824

I updated my app's request headers to also include:

Accept-Encoding: gzip, deflate
Cache-Control: no-cache
Connection: keep-alive

But still no results.

  • It's not just because the EventSource reconnects after 15s? – Johan Stén Sep 3 at 3:04
  • 1
    It reconnects after every 10 records. That's controlled by Horizon. Then when it gets stuck with zero data, my client is reconnecting and getting zero results (except the "hello") every second. (I can configure this 1s retry timeout). – Synesso Sep 3 at 3:19
up vote 2 down vote accepted

curl -H "Accept: text/event-stream" -H "Last-Event-ID: 85025096736968704" https://horizon.stellar.org/transactions shows that the request has valid results. This means the problem is squarely within the reading and parsing logic of the library I'm using. I'm not at the bottom of it yet, but it seems not to be a Stellar problem.

Edit: The library defaults to limiting event line length to 4096 chars. Some Stellar events are much longer than this. https://github.com/akka/alpakka/issues/1183

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.