welp i had the same problem heres part of my coding that has that long delay at the end for some reason.
MML@t96c2cl8cd+fffff4t80d+c<a+a+a+b+t70f4g+a+>t60cd+d+ct40n46c<f4g+2,o1g+1l2c+c+ca+4>c4c+d+g+,o2l2d+1<g+g+ga+g+a+g+;
tried some things what seems to fix the problem is adding the same tempo as the begining at the very end of the melody where all my tempo notes are.
MML@t96c2cl8cd+fffff4t80d+c<a+a+a+b+t70f4g+a+>t60cd+d+ct40n46c<f4g+2t96,o1g+1l2c+c+ca+4>c4c+d+g+,o2l2d+1<g+g+ga+g+a+g+;
if the fix is too simple someone else can find a more complex way to fix it. too lazy to spend 30 more mins to test other things.