-
Couldn't load subscription status.
- Fork 38.8k
Description
Tomasz Nurkiewicz opened SPR-13224 and commented
SseEmitter misbehaves when multiple threads call send() at the same time. Sometimes container fails, but most of the time different messages get interleaved, e.g.:
emitter.send("foo"); //thread A
emitter.send("bar"); //thread B
sometimes results in:
data:data:AB
It happens because emitter.send("A") actually sends three independent messages: data:, A and \n\n. These three messages can be interleaved with messages from different threads. Please either synchronize properly or document clearly that SseEmitter is not thread safe, so that if clients want to use from multiple threads (I think it's quite useful), it must be synchronized manually:
synchronized(sseEmitter) {
sseEmitter.send("foo");
}
Affects: 4.2 RC2
Issue Links:
- ResponseBodyEmitter skips same messages during initialization [SPR-13223] #17814 ResponseBodyEmitter skips same messages during initialization
Referenced from: commits bdb6348