Very short notes cause midi on messages but no midi off messages?

I have the following code inside the processBlock method:

    if (midiMessages.getNumEvents() > 0) {
        std::cout << "=========" << std::endl;
    }
    for (auto meta : midiMessages) {
        auto message = meta.getMessage();
        if (message.isNoteOn()) {
            std::cout << "On " << message.getNoteNumber() << std::endl;
        } else if (message.isNoteOff()) {
            std::cout << "Off " << message.getNoteNumber() << std::endl;
        } else {
            std::cout << "Weird message" << std::endl;
        }
    }

If I played really short notes on my keyboard, I would sometimes get output like this:

=========
On 84
=========
Off 84
=========
On 84
=========
On 84

The on message is sent but there is no off message. The opposite would also happen. This isn’t a problem with my keyboard, I verified that by running LMMS with a simple synth listening to the same midi input, and it responded exactly as I would expect from playing very short notes. This problems is causing my plugin to randomly hold notes forever because it never gets the MIDI off message. Any suggestions for what I could look into that might be causing the problem? It’s currently showing up in a standalone build but I’ve had this problem with exported VSTs in the past as well.

Actually this seems to be happening on long notes. I have yet to nail down exactly what circumstances are causing it, it seems to work fine some times and terrible other times.