RG itself starts up just fine, but on attempting to open any session the delays shown below occur for both opening and closing that session. This has happened only once before about a month or so ago.
As to how to reproduce this, that's not clear. This particular occurrence happened when a Lilypond preview PDF was opened. The session then sent no MIDI to an external keyboard alerting me to something being wrong. Previous sessions were working fine. NB: That same session has worked flawlessly, including Lilypond preview, even the day before. This session may only have been a trigger for the scenario, unless something else occurred just prior to it. Once the problem begins though, it occurs no matter what you are doing with RG after that...including closing and reopening.
Opening a session:
[StartupTester] StartupTester::StartupTester(): URL: "http://www.rosegardenmusic.com/latest-version.txt"
[StartupTester] StartupTester::slotNetworkFinished(): Connection failed: "Host www.rosegardenmusic.com not found"
...
10-15 secs
...
[AlsaDriver] renameDevice(): WARNING: Cannot find device 0 in port map
[Composition] dtor: WARNING: 4 observers still extant:
Closing a session:
[main] Rosegarden main() exiting with rc: 0
...
10-15 secs
...
[AudioPlayQueue] dtor...
[AudioPlayQueue] This tends to be the last thing you'll see on a normal exit.
All the following fail to remedy the situation:
The last one just didn't make sense, unless RG maintained state some place I didn't know about...but there you have it.
Staring at this strange scenario, my eyes drifted to the external keyboard, quietly sitting there apparently doing nothing. It was still on and attached to the computer via USB, and that was the final clue. The only thing which worked was to include the shutdown the external keyboard. Then after restarting everything, sessions opened normally again. But I did see one difference in the logs where that lost time occurred:
That reference to ~SoundDriver was never showing up during the issue. I found the following in the code:
I should point out that during all of this, although ardour used the same JACK instance and the keyboard's audio interface for audio output only, it did not appear to be affected by the problem, but then again ardour was not using MIDI in that session.
This issue occurred again with a different session, and so has nothing to do with Lilypond.
A session was opened from the command line using the file argument. I could see RG had a number of windows on screen, but some were just outlines for the 10-15 secs. In other words, RG was frozen for that time. Then the session appeared to be normal except no MIDI is sent to the external keyboard...or so I thought. A check with aseqdump showed that MIDI is being sent by RG, so presumably not received by the external keyboard.
On opening any RG session, the kernel logs showed:
kernel: sound midiC0D0: rawmidi drain error (avail = 4022, buffer_size = 4096)A similar entry on closing JACK after closing RG.
However, when JACK is started and closed alone, the kernel reports no error. Neither does it do so on just starting RG after JACK...only when a session is opened.
Rather than give up again and shut everything down like before, I stopped both RG and JACK and only removed and inserted the keyboard USB interface. Although registered OK by the OS, I noticed that the keyboard itself was unresponsive even after removing the USB (didn't notice last time), and required shutdown to recover.
My first instinct is that the state of the keyboard is a result of some interaction with messages from RG, since it's relatively new and shown no issues before now. These issues have only begun very recently and the only real change on the computer has been security updates and a few new RG masters. But that proves nothing.
The only search engine reference I see to this type of error anywhere is here:
https://www.alsa-project.org/alsa-doc/alsa-lib/rawmidi.htmlIt states:
But I don't see RG doing anything like this in the code directly?
Modify MIDI Filters has lots of THRU messages to ignore, and I feel like leaning to the cautious side and ignoring just about everything. Perhaps the keyboard is unhappy with some of them and incapable of ignoring them itself? But I would like to first know how to "cause" this buffer drain error intentionally.
Any ideas?
Very strange.
Do you have Midi Sync activated (under preferences midi). I have always had that switched off.
Difficult to know how to narrow down the possibilities here.
Are there any plugins used in the session when the problem occurs ?
Yes...it will be difficult to debug. Just after reporting the bug, I went back to continue and it happened again. I had to shut everything down since the keyboard provides the audio interface, and both JACK and RG are tied to that.
I too have the MIDI sync turned off...in fact all off on that tab. I have no plugins in any of th sessions which were opened prior to and up to when the problem started.
There are two parts to the problem:
Well, with two shutdowns on the same day, I decided to just "change something". What I noticed is that the dozen or so sessions involved did have one thing in common, which I alluded to in the past post...the MIDI THRU filters were not ignoring any of those events for play or record. You (Philip) suggested in bug #1690 that ignoring certain events might help, and that worked out great there. I thought I had adjusted that setting for all sessions i.e. ignore everything by default, and turn them on only if needed. But I missed this particular set. And now when using this set, a mysterious problem where the keyboard itself freezes and does not even respond to any of its switches let alone the actual keyboard. It's not happened for any other sessions. Also note, those sessions have been around for years untouched, same keyboard, same OS and worked fine...so something else has changed.
I've now set all those sessions to ignore THRU events, but have to wait and see if this random bug occurs again...it took a week one time, and just an hour or so of use after the last post.
To be able to reproduce this, I would need information about the buffer error where "sound midiC0D0" tracks ALSA's /dev/snd /midiC0D0. But how is that buffer size of 4096 set? Once we have control of that buffer size, it might be possible to adjust it force the problem out of its apparent randomness.
If you can repeat this fairly regularly, you can try running rg in gdb, causing the delay, then pressing Ctrl+C in gdb to stop rg when it hangs. Do a "bt" to get a backtrace. That should tell us where the issue is. rg has multiple threads, so it might be a little trickier than this, but it should be doable. Let me know if you need more info.
It's not predictable yet. But after it occurs, any RG instance opened is affected, so yes using gdb during that launch could prove very useful for the freezing part. However, I generally do not keep development tools on the box in question, although if the problem occurs I can install it for that time...only MIDI is affected during all of this.
I can probably figure out the steps but the bug bound to catch me out in the middle of a session. So, assuming that gdb and its dependencies are around AND any attempt to open an RG instance freezes, what are the exact steps I should take before starting RG in that scenario? Armed with that, I will revert all of the sessions back to using THRU, assuming that has anything to even do with this, and wait out the bug.
You'll want to use a debug build for this. I assume you are already running debug builds to get debug output, so you should be ok.
Run rg with gdb like this:
At the gdb prompt:
(gdb might ask some questions about debuginfo. Just say no.)
rg will start as usual. When it hangs, switch to the terminal where gdb is running and press Ctrl+C. From here you can do a backtrace (bt)
and look at the threads (info threads).
Use the "t" command to select a thread and then bt to get the backtrace
Since we aren't sure which thread is hanging, we'll need the backtrace from each thread.
Don't worry too much about missing file or name warnings. You'd need to load up the symbols for all the libraries, and that probably won't help all that much. We're more concerned with what rg was doing when it got stuck. That should tell enough of the story to figure out what's wrong.
Note that you can experiment with this when rg isn't crashing. Just Ctrl+C in the gdb terminal at any point during a normal rg session to get some practice with gdb.
Use the quit command to quit gdb.
I haven't had to use gdb for a long time, so your instructions are very helpful and clear. I decided to get the gdb install over and done with beforehand...it's pretty a light install. I also reverted all the sessions in question.
So, it's just a matter of waiting. I'm sure the gremlins noticed the gdb install, so there's a chance they're smiling and have head to ground to wait me out...you know how they are. But then again, they're always up for a challenge! :-)
So, I was right...the gremlins had plans of their own. No matter what I did, I could not get this bug to reoccur, even though I believe I've repeated everything as before every day since. I even tried slight variations just in case. Nothing. And it should have occurred by now.
Two things have changed, although it's difficult to know if they are involved:
On the bright side, while doing something completely different, I did get RG to freeze, although you will see that not only is the scenario different, but the keyboard did not freeze, and I could still use MIDI after the 10-15 secs passed. In any case, gdb rode to the rescue as per earlier instructions in this bug thanks to @tedfelix, and I will post that next.
I wasn't even using the problem sessions at this time, just checking another audio interface. These may be steps to reproduce, but are just the scenario as it unfolded:
NB: When the bug was opened, no other audio interface was involved, but I was using the rg file method every time. Also note, that in that case, even opening RG normally froze, so it's not the same scenario, but I think you may be able to reproduce this one.
I followed the instructions provided earlier and hope they reveal something in the attached gdb output. One other total guess is worth mentioning, based on this and what occurred before. This extra audio interface does support MIDI, but I did not have any cables connected to it. In the previous scenario, when the keyboard itself froze (reasons for that still unknown), I assume that its MIDI was unavailable. RG did send MIDI when it finally opened after the freeze (checked with aseqdump), but the keyboard meter levels did not respond to MIDI and I heard nothing. At that time, I could hear audio sent by ardour to the keyboard. That may relate the two scenarios...an audio interface capable of receiving MIDI, but is not responding. Then RG freezes with frames around missing windows, and no clue as to what's going on. But that is pure speculation.
So it looks like the issue is in
AlsaDriver::removeAllDevices(). The only thing this does is asnd_seq_delete_port()which does do some waiting until all port accesses end. This might be where we are getting stuck. Maybe some device is blasting us with inputs? Or rg is blasting some device with outputs at the time? Or something else?I've added some diagnostics to the code. Instructions to enable:
~/.confg/rosegardenmusic/Rosegarden.confin your favorite editor.Now when running Rosegarden, you will see output like this:
In the future when it hangs, it should show a port name (like the "out 1..." above) but no "port deleted" as it is waiting for the
snd_seq_delete_port()to end. This diagnostic serves two purposes:If this logging seems like it might be generally useful in the future, we should give it a more permanent location in the .conf, e.g. [Debug] alsaDeletePort=true.
Related
Commit: [d9d5a3]
I'll download the new master for the above instructions. In the meantime, since I always see the following in the logs even with no extra audio interface, I might as well ask what information this entry in the logs is trying to convey:
[AlsaDriver] renameDevice(): WARNING: Cannot find device 0 in port mapIn the rg file itself, there is always a device 0 tag and mostly its direction is record:
<device id="0" name="MIDI input system device" direction="record" variation="" connection="keyboard" type="midi">This entry appears even in sessions where I don't record MIDI...in fact, the entry shows up when starting rosegarden and has done so for all versions I can recall. Is that normal? Seems not, or why else the warning.
And for the question of what is unusual about the MIDI device attached to that port? Quite frankly nothing that I have not mentioned already...it only occurs when the second audio interface is added as described below:
You should be able to reproduce that if you have any audio interface around, which you would normally use to connect a computer to a MIDI device. Just plug that in after your normal audio interface (i.e. two interfaces just to match this scenario) and make sure that you don't have a MIDI attached. Then start RG. If it hangs, then the scenario is confirmed. If not, then sure...something local is going on here
This message is issued at file read time when we are reading a device tag. I added the name to the logging and it appears to only happen for input ports. Those are created elsewhere and named some variation on "record in".
It's a harmless message that can be ignored. It should probably be suppressed for input ports since they are created in a different manner.
Last edit: Ted Felix 2025-09-03
OK...results. Well, it's not news. Rosegarden freezes exactly where you thought it would:
Why removeAllDevices? Then it occurred to me. An important requirement of this freezing is that RG is first opened, which it does normally i.e. no freeze. But then you attempt to open another session, and the current one (even the autoload studio) is closed, leading to a removeAllDevices.
Requirement 1:
This scenario is most easily achieved by supplying the target rg file via the command line. RG first opens the default studio, and then closes that to open the target session.
But that is not enough, and at this point, I still don't think it's local issue of either interface. Both work normally on their own. This is what I did next, since it's reproducible here:
Setup:
Steps
All repeatable, except that when first setting up or even leaving the computer unattended, it does take about three openings before the freeze cuts in. After that, it freezes first time, every time.
Requirement 2:
Both interfaces need to be present, and freezing only occurs after RG starts normally and another session is opened manually, or the same thing in one step via command line.
Two things does bother me though
I mentioned in a previous post that connecting the MIDI cable to MIDI Out 2 to an available external keyboard might be a factor. Well, I did try to connect to MIDI Out 2 to the MIDI in of Keyboard 1 when both USB interfaces were present. However, the keyboard can only accept MIDI from either the USB interface OR via its MIDI ports. So with both interfaces connected, there is always one that will not get access to the keyboard even though RG thinks it has. Therefore RG could still freeze because it did not get a timely response.
So, you have all I know in order to recreate a similar scenario unless you want to add more debug statements.
Last edit: Ted Felix 2025-10-28
Since the hang is happening way down in
ioctl()calls in the device driver, this feels like an ALSA and/or driver issue. Or maybe a hardware issue. I tried to reproduce and could not.I used an M-Audio MIDISPORT Uno for the MIDI interface and a Yamaha MM-6 for the keyboard. Followed your procedure. No delays at any point. I'm running Linux/ALSA 6.14.0 from Ubuntu (6.14.0-29-generic).
General USB troubleshooting... I've had trouble with MIDI devices plugged into USB3.0 ports. Try using different USB ports on the machine. Avoid the blue (3.0) ones, stick to the black (2.0) ones. Use different USB cable(s).
Do you have a third MIDI USB device? If so, try mixing it in with the others:
That might point to either 1 or 2 being the specific culprit that doesn't get along when combined with others.
Your suggestions make perfect sense. And the fact that you can't reproduce it is useful too and points to something at my end.
Funny enough, your mentioning MIDISPORT reminded me that I have a USB MIDISPORT 2X2 lying around somewhere in a box, which I've not used in over a decade. I'll dig that up and it will settle everything. As for trying a USB 2.0 port, unfortunately all four of my ports are the blue USB 3.0 type...a sign of the times.
But remember that with those same USB ports, on its own, the keyboard with built-in audio interface works perfectly with RG. And the other audio interface, when connected to yet another keyboard (in storage, and hard to get to), worked perfectly with RG too. Both, independently, can play and record with no issues. So, it can't be the cables, port types, audio interfaces or equipment as such. It's only when "both" USBs are plugged in that RG freezes. And although JACK is known for audio, I can connect two different JACK servers to the audio interfaces when they are both plugged in, and JACK starts up, listens on each independently and reports no issues on either. Then again, it's not trying to do anything with MIDI. Ardour is also MIDI aware and it launches and quits without freezing, but I've not used its sequencer in years. In the end, it might well be what you suggested i.e. an ALSA issue after all.
In the mean time, I'll address the second point in my last post which bothered me a bit, as I so quaintly put it. This bug would not have occurred if RG hadn't noticed the other audio interface, which I had plugged in for an entirely different purpose. So, RG is freezing up when apparently trying to deal with an audio interface which I didn't want it to have anything to do with. Dredging up my post in bug #1686 (yeah...over a year ago), I'll paste the relevant part here to save you time:
I guess to make life simple for first time users, it must be seeking out any MIDI interface and adding to its device list, as evidence by the fact that both of the audio interfaces are shown in the Manage MIDI Devices window...aseqdump would show up there too if running, albeit with the word write in parenthesis when I saw it last. Then all may be subject to that removeaAllDevices, when that should only apply to the ones that RG has jurisdiction over.
Has another approach, which I find cleaner, been considered? What I suggest follows:
Now there is no guessing what the user wants to use. They keep their default MIDI device in the autoload studio, and can scan for and keep other devices in the sessions in which they need them.
And of course, in my scenario RG may not have frozen, assuming (big assumption) that if RG didn't know about the other audio interface this issue would not have occurred. I would not have cared, because I had no intention of using that temporary interface with RG anyway. And seqdump instances galore would not show up in RG uninvited. It's just a thought or two. Comment?
Anyway, I can't wait to do that "divide and conquer" test you suggested. I'll return with the results of the MIDISPORT permutations test.
There are complications due to apparent randomness in the results. At first, swapping in the MIDISPORT as the second interface appeared to avoid the bug. I nearly sat down to report that after an initial 10 starts trouble free. But somewhere along the line rosegarden froze with that too. But only once. I then repeated it a dozen more times and no freeze. At least that never happens in the real scenario...there, it's repeatable first time, every time. I did track down one source of the apparent randomness. It involves what I mentioned in the last post i.e. RG seeking out all MIDI devices on launch and adding them to its list.
The only thing certain for the reported scenario is that at least the default studio and the session chosen do have the same preferred device. But I've been thrown for a loop so far because I've been plugging and unplugging the various audio interfaces, and when the preferred device is not available, RG picks one of the others that happens to be first...and that is not necessarily this scenario...it just increases the possibilities of apparent randomness. Now I'm unplugging all of them and adding them in a fixed order to match the original scenario.
It's too early for conclusions, but it's beginning to feel like it might still be an issue with the keyboard via the USB interface, not the keyboard itself. The MIDISPORT is connected directly to the same keyboard via MIDI cables so I will be able to take the keyboard interface out of the equation. The only way to prove that is to alter the autoload and second session preferences to be MIDISPORT so that at least is fixed, and use the third audio interface to create the two interface scenario.
I can't seem to get RG to play along with creating this scenario with a new MIDI device. The problem is its handling of multiple MIDI interfaces. What I noticed is the following:
Question: Does that happen in your case?
Question: Does that happen at your end?
You can try keeping the MIDISPORT constant and adding any other MIDI devices you have around, and the question is does MIDISPORT remain selected regardless? If not, how is RG deciding which device to pick "for the user", if it's not using the one in the rg file and has multiple in its list. It's not the first in the list either from what I've seen.
Finally, how do I tell RG to use only the device I specify, and if that's not there then go to "No Port"? I get the feeling that can't be done though :-) This feels like bug a rehash of bug #1687.
Finally, I found the DNA of this bug :-) It's simple, and I think I can get you to reproduce it easily. Right now, I can now turn it on and off like a light. I had the advantage because of its repeatability at my end. And it is in fact a rehash of bug #1687 as mentioned in the last post. You'll need circumstances of that bug, which basically is a summary here:
When I first used RG, I had AudioInterface-1 and RG started with a default studio rg file field with: connection="" for play and record. And so that remains unless the user actually opens RG with a MIDI device and saves that session as the new default studio, which is what I did. So, my default studio rg file contains:
These connections appeared in the Manage MIDI Devices window and was the same for all sessions created using that default studio. Then time to retire AudioInterface-1 in favor of Keyboard-1. So now the default studio still has the entries above...no way to change that except manually as far as I know. But, new session rg files contain the following since only the new interface is plugged in:
Somewhere over time, perhaps while debugging bug #1687, the default studio's play device became that of the new keyboard, so it's rg file became the following i.e. the connections do not match. I suppose there is nothing wrong with recording from one interface while play to another, but that was not my intent:
All new sessions created since then, inherited these mixed settings, even though AudioInterface-1 was never plugged in. And to date I have not detected any issues until I resurrected the old AudioInterface-1, not to use, but just plugged it in. Somehow, that removeAllDevices() is adversely affected by the mismatch which leads to RG freezing. This is the key to the issue when both interfaces are plugged in:
And don't forget that it involves not just starting that studio , but opening another session (not sure if the added mismatch of the latter plays any role).
Going back to the inability, as far as I know, to get RG to empty that connection string or keep it up to date, I will have to do that myself manually i.e. set both record and play to empty once and for all in the default studio. Then sessions created from that will have identical connections for their play and record based on whatever device happens to be around.
Allowing the original interface to remain in sessions indefinitely, with no way to change them, is probably not a good idea, in case some unexpected circumstance or dependency turns up like the current scenario.
See if you can reproduce the bug this way and let me know. Is it a bug, or just misconfiguration i.e. are users allowed to pick different play and record connections anyway?
Last edit: Ted Felix 2025-10-28
This is very perplexing. The hang is being caused by the initial clearing of connections before we read the .rg file. So the contents of the .rg file can't be causing the issue. Unless the .rg file is loaded twice. Then it will only happen the second time. Unless you have the same setup in your autoload.
Can you send me a screenshot of the "Manage MIDI Devices" window prior to the load that hangs? This will give me an idea of what removeAllDevices() is actually starting with which can be completely different from what is in the .rg file.
Yes...it's troublesome and I have not completely given up on it. I tried a few things since and it's only occurred once since the last post over a month ago. I even thought it had gone. Then wham! "Did you miss me?"
My last post about the "DNA of the bug" described how to duplicate the issue every time but not via normal RG usage. It can be done using your own OS, two audio interfaces to your own keyboard, one of which was a MIDISPORT which you mentioned.
If not, then:
If (1), well I doubt there is anything you can do...perhaps it just freezes occasionally and at random of its own accord. Remember, the keyboard itself becomes unresponsive until restarted. That is odd, although it could still be the result of something happening at its USB interface. Recall that error which happens at the same time, but does not show in the RG logs, but in the kernel logs:
kernel: sound midiC0D0: rawmidi drain error (avail = 4022, buffer_size = 4096)Unless RG is mishandling a low-level resource in some way, then something else is causing that error, which then appears in RG as a freeze and affects the keyboard i.e. ALSA/USB interface.
If (2), I'm using debian bookworm 6.1.0-40 whereas trixie is at 6.12.48. I am still testing trixie and will soon upgrade
Your mentioning of the .rg file being loaded twice is interesting because the scenario where this was first noticed, involves the following sequence of events:
And that sequence is scripted for the sessions I want to work through without filemanger hunting.
Each time RG is restarted, even though via command line, I suspect the default studio is still opened in between? I don't actually see it...only the final session on the command line. Hence, possibly the two rg files you mentioned? And as a script, timing might be involved. The only problem is that I can go through a dozen sessions like that for a month and only get stuck once. So, it just doesn't pan out as a cause.
Well, there are the two questions above, and I suggest leaving this bug open until I upgrade. The OS error messages may well be clearer if the problem still occurs and right now it's rare enough to get by with and no one else has reported a freeze.
There are surprisingly few references to drain error. And it's not certain whether this occurs just prior to, after or even at the same time as the bug report. But it is certainly always shows up in the kernel logs at about that time.
I found this link which itself contains familiar language i.e. "stopped responding" and "taking down the stack":
https://github.com/hathach/tinyusb/issues/735
In it there is another link to a related issue mentioning issues when not dealing with sent/received MIDI data correctly:
https://github.com/hathach/tinyusb/pull/618
In that last link, they also mention MIDI, USBs, SysEx and blocking. Their short discussion may provide you with some clues, assuming the problem has anything to do with RG.
Anyway, it's just info. Waiting for the upgrade to trixie will provide useful information.
I found something odd when RG is opened via the command line rg file argument. As mentioned previously, to avoid JACK errors when kill is sent to RG in a script, I use wmctrl to close it instead before another command line start:
wmctrl -c "- rosegarden"After that, I was temporarily using a sleep of 1 sec to allow RG to close down, but never returned to update my script. That was a mistake...it can take longer...occasionally...even though it is not on the screen. So, I went back to favoring state to determine if RG is actually closed. It's still not perfect, but I use the ps command in a while loop to check, along with a short sleep. And I was surprised to see how often it took time closing, more importantly along with the following difference in the RG logs.
Normally, when RG is started, the default studio ends with the lines above the dots in the following log. And when another session is opened via the Recent list, the observers WARNING appears (harmless).
On the other hand, when the wmctrl command is used in a script, followed the sleep loop before starting another command line, RG has an extra, unexpected line. I appended my own logging during the sleep loop:
I usually only see that status change with select play, where it goes from 0 to 1, and when I stop RG and it changes from 1 back to 0. Naturally, I assumed it was a boolean.
The obvious question is what is the meaning of a status of 7? Why would that show up presumably while shutting down?
It's probably nothing, since this thread is full of red herrings, but I might as well ask, since timing often leads to apparent random issues which are difficult to reproduce.
7 is quit.
Well, the issue occurred with trixie too. Assuming that enough of the OS, including ALSA has been updated since bookworm, then the problem survived the upgrade. That still leaves RG, and of course the keyboard, and possibly JACK since it owns the keyboard USB interface.
But there was an important change of behavior relevant to this thread. RG always froze for 10-15 secs (probably just under 10s in reality). But now it was more of a hiccup lasting a split second. If I had not been sensitized to the current issue, I would not have noticed. Just the thought crossed my mind and instead of hitting play in RG, I reached for the keyboard buttons...frozen. And then no sound from RG on play.
Also important is that the midi drain error was not in the journal when the non-sounding RG was open. I always figured that the problem must occur while the previous RG is closing or while the next launch was in progress. Because neither RG nor JACK have timestamp logs, it was never clear when that drain error appeared, but it was always there.
Then I made a mistake. I remembered to close RG first and the drain error was not in the journal...and I intended to wait much longer (full 2 mins) to be sure it hadn't just been delayed. I instead turned off the keyboard, even forgetting JACK was still up. When I checked the journal, the drain error was there along with the usual kernel complaints about xhci_hcd. In any case I have to wait all over again.
Conclusion: RG always froze for a lengthy time, so if that does not occur next time then this bug, by description, no longer occurs in trixie. Furthermore, I built using the same master zip used in bookworm, except now it's qt6 and gtk3. That would mean that something outside of RG must have changed.
Let's wait for the final curtain call though.