server: event file plain read now uses per-fid subscription
Plain reads (without writing a filter first) now get a per-fid subscription with '*' filter, identical to 'echo * | rdwrs event'. This fixes event loss — the old EventStream path overwrote events when multiple arrived before the reader consumed them.
This commit is contained in:
parent
c96ccd51e8
commit
cd94cdf259
|
|
@ -598,7 +598,7 @@ func read(root *fs.Tree, cs *connState, fc *plan9.Fcall, ctx context.Context) *p
|
||||||
}
|
}
|
||||||
|
|
||||||
if entry.StreamMode() {
|
if entry.StreamMode() {
|
||||||
// Special handling for event file with filter
|
// Special handling for event file — always use per-fid subscription
|
||||||
if path == "event" {
|
if path == "event" {
|
||||||
cs.mu.RLock()
|
cs.mu.RLock()
|
||||||
f, fidOK := cs.fids[fc.Fid]
|
f, fidOK := cs.fids[fc.Fid]
|
||||||
|
|
@ -609,20 +609,22 @@ func read(root *fs.Tree, cs *connState, fc *plan9.Fcall, ctx context.Context) *p
|
||||||
eventCh := f.eventCh
|
eventCh := f.eventCh
|
||||||
f.mu.Unlock()
|
f.mu.Unlock()
|
||||||
|
|
||||||
// If filter was written, use filtered subscription
|
// Create subscription on first read (filter defaults to "*" for all events)
|
||||||
if filter != "" && eventCh == nil {
|
if eventCh == nil {
|
||||||
// Create subscription on first read after write
|
if filter == "" {
|
||||||
|
filter = "*"
|
||||||
|
}
|
||||||
subCtx, cancel := context.WithCancel(ctx)
|
subCtx, cancel := context.WithCancel(ctx)
|
||||||
ch := session.SubscribeEventsFiltered(subCtx, filter)
|
ch := session.SubscribeEventsFiltered(subCtx, filter)
|
||||||
f.mu.Lock()
|
f.mu.Lock()
|
||||||
|
f.eventFilter = filter
|
||||||
f.eventCh = ch
|
f.eventCh = ch
|
||||||
f.eventCancel = cancel
|
f.eventCancel = cancel
|
||||||
f.mu.Unlock()
|
f.mu.Unlock()
|
||||||
eventCh = ch
|
eventCh = ch
|
||||||
}
|
}
|
||||||
|
|
||||||
if eventCh != nil {
|
// Read from subscription — blocks until event arrives
|
||||||
// Read from filtered subscription
|
|
||||||
select {
|
select {
|
||||||
case ev, ok := <-eventCh:
|
case ev, ok := <-eventCh:
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
@ -643,7 +645,6 @@ func read(root *fs.Tree, cs *connState, fc *plan9.Fcall, ctx context.Context) *p
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Default stream handling (no filter)
|
// Default stream handling (no filter)
|
||||||
cs.mu.RLock()
|
cs.mu.RLock()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue