The current detection of MIDI disconnects can be wonky, see this issue in the go-midi project: https://gitlab.com/gomidi/midi/-/issues/42