squat / generic-device-plugin

A Kubernetes device plugin to schedule generic Linux devices
Apache License 2.0
210 stars 23 forks source link

deviceplugin: fix panic when server is stopped #41

Closed squat closed 1 year ago

squat commented 1 year ago

Currently, whenever the server is stopped, the server's goroutine will panic because the channel on which it needs to send its return value is closed before the value is read/sent.

This commit fixes the issue by inverting the closing of the channel and letting the sender, i.e. the server's goroutine, do the closing of the channel. This ensures that the channel is only closed after the return value has been sent. On the receiving side, the channel is drained to ensure that the goroutine has finished before moving on. Note that this draining will not block because either it will receive an error from the server or it will receive nothing because the channel was closed.

Fixes: #37

Signed-off-by: Lucas Servén Marín lserven@gmail.com