radu-matei / websocket-manager

Real-Time library for ASP .NET Core
https://radu-matei.com/blog/real-time-aspnet-core/
MIT License
452 stars 183 forks source link

Investigate Kestrel exception when middleware is the last in pipeline #2

Closed radu-matei closed 7 years ago

radu-matei commented 7 years ago

When this is the last middleware in the pipeline, Kestrel throws an unhandled exception

radu-matei commented 7 years ago

The exception comes from calling next.Invoke() after writing to the stream (check the documentation, pretty much RTFM)

Basically, even if WebSockets don't go through the pipeline as HTTP requests do, the initial handshake and upgrade mechanisms are HTTP, so I was writing to the response stream and also invoking the next middleware.