Yes, if the note_off message is sent directly after note_on (milliseconds), its length is so short that you’ll have the impression the note message is missed but I don’t think that’s the case (it also depends on how the external instrument handles midi messages, a Nord Drum 2 for example doesn’t really care about notes off). You can check with a software like Midi monitor or use a simple print() somewhere in your function to check in the console if the message is sent.
There are many ways to give a length to your note message. One way is to use a metro. It really depends on what you’re trying to achieve, which source is triggering the note/driving the sequencer etc.
My answer is a bit messy but I’d be happy to help via PM or in another thread if you need 
A bit off topic, but generally, I use something like this to keep track of the active notes. It's easier for handling the notes on and notes off
notes = {} -- store the active notes in this table
m.event = function(data)
local d = midi.to_msg(data)
if d.type == "note_on" then
local note = {d.note, d.dvel}
notes[note] = note
elseif d.type == "note_off" then
local note = d.note
notes[note] = nil
end
end
Then use two functions one for playing (note_on) and another one for stopping the notes.
Looking at loom.lua, Mark Eats seems to do something like this, too. See lines 203, 225 and 508 of the script