Skip to content

[BUG]: MidiSrv's lazy-loading causes music applications to hang on first use #1076

Description

@sagamusix

Report pre-requisites

  • I have searched this repo for existing issues to confirm this is not a duplicate
  • I agree to follow this project's Code of Conduct

Clarity and Disclosure

  • I confirm that any AI analysis included in this report is clearly called out / tagged as AI-generated with "AI Generated Content". Reports with suspected AI content may be closed if not disclosed.
  • I confirm that I will quickly follow-up to questions or requests for additional detail, otherwise the issue may be closed

Windows Version

Windows 11 25H2

Type of bug

  • Windows doesn't recognize MIDI device (doesn't show in device manager)
  • Application doesn't recognize MIDI device or ports
  • Cannot update firmware on MIDI device (specify device, app, and firmware info)
  • MIDI device is recognized, but cannot send or receive messages
  • Sent or received MIDI messages are corrupted
  • Application not working as expected
  • MIDI 1.0 ports not named as expected
  • Performance not as expected
  • Localization issue (incorrect or missing language for Windows running something other than en-US)
  • General application crash or hang
  • MIDI Service crash or hang requiring Windows reboot
  • Windows bugcheck / BSOD (please include in the areas below the device id from Windows Settings About page or a link to your crash dump uploaded to a sharing service)
  • Other or Unsure (please indicate in additional notes section below)

Location

  • Application using WinMM MIDI 1.0 (Classic API). Name provided below.
  • Application using WinRT MIDI 1.0 (Windows 10 MIDI). Name provided below.
  • Application using Windows MIDI Services API (sometimes referred to as MIDI 2.0). Name provided below.
  • Other app/DAW/tool. Not sure about which API or SDK it uses. Name provided below.
  • Windows MIDI Services tools like MIDI Settings, Console, etc.
  • Directly in Windows MIDI Services SDK (for Developers only, please provide repro code)
  • General Windows shell (Device Manager, Settings, Services, etc.). Name provided below.
  • Windows MIDI 2.0 Class Driver (usbmidi2-acx.sys)
  • Windows MIDI 1.0 Class Driver (usbaudio.sys)
  • Vendor-provided MIDI driver (please provide details below)
  • Other or Unsure (please indicate in additional notes section below)

Application Name and Version

OpenMPT

MIDI Device

n/a

Vendor Driver

n/a

Output from the MIDI Diagnostics Tool

n/a

Repro

  • I confirm that I was able to reproduce this issue using a simple app like midi.exe, midi1monitor.exe or Pocket MIDI
  • I tried but was unable to reproduce this issue using a simple application

Your personal observation that led to the bug report

It appears that as of recently, Windows 11 runs a MIDI service component (MidiSrv) only on-demand, i.e. when an application first calls any of the MIDI API functions, such as midiInGetNumDevs(). Even on a Windows 11 system that has no MIDI devices at all attached (i.e. the only MIDI device listed by MMSYSTEM is the GM wavetable synth), the MIDI API call in question hangs for about ten seconds. Often, as is the case in OpenMPT, MIDI devices are enumerated on the GUI thread, to present a list of available MIDI devices. So this inevitably leads to a GUI hang, or the requested information not being available in the GUI.
If the application in question also suppports MME audio devices, any interaction with MME audio APIs such as enumerating audio devices appears to access the same internal structures as the MIDI device code, so even if you move your MIDI device enumeration code to a separate thread, the audio device code will still be blocked for the same duration if it happens to run at the same time (e.g. because the application enumerates available audio and MIDI devices on startup).

Steps to reproduce

See description above.

Additional notes

I fully understand that the MIDI component is not important to every Windows 11 user, so it is not started automatically to keep startup times lean for such users. However, this comes at the expense of music producers who now either have an inevitable hang, or have their MIDI devices being unavailable on first use. I wonder if the MIDI service could instead be started with a delay and low priority, so that it does not affect Windows 11 startup time for regular users, but doesn't block MIDI device enumeration and other API calls by the time a user is likely to use these APIs for the first time.

I tried to see if I can request the service to be started programmatically when launching OpenMPT, but it appears that this is a privileged operation that a non-admin Windows user cannot invoke. So my only workaround right now is to call midiInGetNumDevs() on a separate thread while OpenMPT starts up, and then hope that the user doesn't do anything that would require MME audio or MIDI devices to be enumerated, otherwise the GUI will just freeze.

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions