-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Faulty line splitting logic for part detection with \r\n #17
Comments
Seconding this, as sse.js is not working with |
I think I'm having the same issue. If @mpetazzoni doesn't address this should the thing be forked? |
Made the modifications as per - mpetazzoni#17
This should be fixed by #35, now merged. Will release shortly. |
@mpetazzoni, Otherwise it was not parsing the value of the |
@zoltan-fedor Can you share an example payload that doesn't parse correctly? |
Sure, I am using Python package
There isn't really an easy way to see the events arriving, due to #39 (comment) But I needed to change parsing rule |
Since you're modifying sse.js anyway, can you have it log/dump the received |
I too find OPs regex works better:
The following is an example event emitted by sse-starlette and how it splits with the two regex
|
@cwelton Thanks! I'm really curious, why would those two regex behave differently? Aren't they supposed to be equivalent? |
No, the issue is that |
I just wasted a ton of time wondering why when I upgraded sse.js to 2.1.0 I was losing all messages. I too used sse-starlette and thought maybe the line breaks were still an issue. Turns out versions 2.0.0 and under if you addEventListener() for "message" events, sse.js will react regardless if the SSE event in question is of that type. In other words, if it sees:
it will react accordingly, for it is a message of an anonymous type, and for event like this:
it would STILL react in the "message" event listener, because hey, it's a message, I guess... but this one, however, is of event type "log". With sse.js 2.1.0, "message" event listeners no longer act as a "catch all", and the above does not get caught at all, which greatly confused me. However, once I did addEventListener() for "log" instead of "message", voila! Messages are being received again. 😅 Just sharing in case it saves somebody some headaches. |
This code does not work as intended: https://github.com/mpetazzoni/sse.js/blob/master/lib/sse.js#L114
data.split(/(\r\n|\r|\n){2}/g).forEach(function(part) {
If a stream uses \r\n as the separator, then this will not work because \r\n{2} is not matched but \r followed by \n is matched since you're doing an OR regex.
The regex needs to be
/(\r\n\r\n|\r\r|\n\n)/g
if you want this to behave as intended.Otherwise you end up with this incoming data:
being interpreted as a single event with no data as you get ['event: foo', '', 'data: bar']
Consequently I think the code at https://github.com/mpetazzoni/sse.js/blob/master/lib/sse.js#L141
chunk.split(/\n|\r\n|\r/).forEach(function(line) {
may need to be reviewed also.. it should probably prioritize \r\n to avoid such issues, i.e.
\r\n|\n|\r
The text was updated successfully, but these errors were encountered: