jellyfin / jellyfin-plugin-tvheadend

https://jellyfin.org
MIT License
32 stars 19 forks source link

Recieve handler thread pinned at 100% #73

Closed Charlese2 closed 8 months ago

Charlese2 commented 8 months ago

The ReceiveHandler will just spin if the remote closes the connection as Socket.Receive() just returns immediately with 0 bytes instead of blocking.

https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/5c29b9907d74e6b47a940fc61ea26a7888cd52db/TVHeadEnd/HTSP/HTSConnectionAsync.cs#L387

https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.socket.receive?view=net-6.0#system-net-sockets-socket-receive(system-byte())

If you are using a connection-oriented Socket, the Receive method will read as much data as is available, up to the size of the buffer. If the remote host shuts down the Socket connection with the Shutdown method, and all available data has been received, the Receive method will complete immediately and return zero bytes.

Charlese2 commented 8 months ago

image Most of the time the cpu seems to be in the kernel code of the recvmsg syscall while it is spinning in the while loop.