thestk / rtmidi

A set of C++ classes that provide a common API for realtime MIDI input/output across Linux (ALSA & JACK), Macintosh OS X (CoreMIDI) and Windows (Multimedia)
Other
981 stars 271 forks source link

Crash VirtualPorts #210

Open ledvinam opened 4 years ago

ledvinam commented 4 years ago

We are facing issue when our app crashes then opened virtual ports stay opened forever. Is there a way to call openVirtualPort with behaviour it that name already exists you return that endpoint instead of creating new one.

Let's assume I opened virtual port "PORT1". Now my app crashed. I reopen my app and it creates again virtual port "PORT1" so now there are two ports with the same name in the system. Which is most likely not the behaviour one would expect. I would expect if that virtual port is already open and I call openVirtualPort again with exact same name that you return the existing one. That way I will be able to close it even if my app crashed. Does it make sense?

keinstein commented 4 years ago

Which backends do you use? Probably not JACK as it would rename your port silently to make the name unique. This sounds to me as a bug in the backend (if it is not MacOS), not in RtMidi. Ports are owned by the clients that register them. If someone else can destroy them this may crash the owning app. So this should be forbidden. Does the orphaned port disappear after a while?

bome commented 4 years ago

I've looked into this. He uses our fork for BMIDI on Windows ( https://github.com/bome/rtmidi ). It does not crash. It merely throws an RtMidiError exception which he does not catch in the calling code.

@ledvinam if you can confirm this, you can close this bug.

ledvinam commented 4 years ago

Hi, yes it is osx. So the issue is that if our app crashes the ports stay open since we dont have chance to close them and when we open our app again the new set of ports are oppened and we are never able to close the old ports from crashed app except by restarting osx. Solution is as I suggested if that oppened port is virtual and already exists return that one instead of creating new one.

On Wed, Sep 18, 2019, 17:13 Tobias Schlemmer notifications@github.com wrote:

Which backends do you use? Probably not JACK as it would rename your port silently to make the name unique. This sounds to me as a bug in the backend (if it is not MacOS), not in RtMidi. Ports are owned by the clients that register them. If someone else can destroy them this may crash the owning app. So this should be forbidden.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/thestk/rtmidi/issues/210?email_source=notifications&email_token=AHE4XIVNK5W3O5PDGYAG5MLQKH5LPA5CNFSM4IXYJNW2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD67R74Q#issuecomment-532619250, or mute the thread https://github.com/notifications/unsubscribe-auth/AHE4XIWCTZPTJ5JH577R5W3QKH5LPANCNFSM4IXYJNWQ .

On Wed, Sep 18, 2019, 17:13 Tobias Schlemmer notifications@github.com wrote:

Which backends do you use? Probably not JACK as it would rename your port silently to make the name unique. This sounds to me as a bug in the backend (if it is not MacOS), not in RtMidi. Ports are owned by the clients that register them. If someone else can destroy them this may crash the owning app. So this should be forbidden.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/thestk/rtmidi/issues/210?email_source=notifications&email_token=AHE4XIVNK5W3O5PDGYAG5MLQKH5LPA5CNFSM4IXYJNW2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD67R74Q#issuecomment-532619250, or mute the thread https://github.com/notifications/unsubscribe-auth/AHE4XIWCTZPTJ5JH577R5W3QKH5LPANCNFSM4IXYJNWQ .

ledvinam commented 4 years ago

Not true Florian. We use your source code only for windows.

On Wed, Sep 18, 2019, 17:27 Florian notifications@github.com wrote:

I've looked into this. He uses our fork for BMIDI on Windows ( https://github.com/bome/rtmidi ). It does not crash. It merely throws an RtMidiError exception which he does not catch in the calling code.

@ledvinam https://github.com/ledvinam if you can confirm this, you can close this bug.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/thestk/rtmidi/issues/210?email_source=notifications&email_token=AHE4XIWAYJP6W2IU2HKVTZDQKH7CTA5CNFSM4IXYJNW2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD67TFLQ#issuecomment-532624046, or mute the thread https://github.com/notifications/unsubscribe-auth/AHE4XIWMINECEWN57EJAZJ3QKH7CTANCNFSM4IXYJNWQ .

keinstein commented 4 years ago

@ledvinam Is your source code public? Does your application crash due to an unhandled exception or because of some segmentation fault? In the former case you probably use new and delete for managing your object. In that case your should wrap this pointer in an object with a proper destructor that destroys the RtMidi object upon destruction. That object should live on the or be a global variable. In the latter case your should assure that the RtMidi pointer is initialized as nullptr and the RtMidi object gets constructed from the main function (or something that is executed during main).

ledvinam commented 4 years ago

We compile it into dll and use it in Unity. The issue is if our unity app crashes for whatever reason connected or not connected to rtmidi we simply are unable to close the ports.

On Wed, Sep 18, 2019, 18:00 Tobias Schlemmer notifications@github.com wrote:

@ledvinam https://github.com/ledvinam Is your source code public? Does your application crash due to an unhandled exception or because of some segmentation fault? In the former case you probably use new and delete for managing your object. In that case your should make shure that

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/thestk/rtmidi/issues/210?email_source=notifications&email_token=AHE4XIVEYSY2FVM54N4AT73QKIC35A5CNFSM4IXYJNW2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD67VTVQ#issuecomment-532634070, or mute the thread https://github.com/notifications/unsubscribe-auth/AHE4XIWXMKQKPDEL6CDL56LQKIC35ANCNFSM4IXYJNWQ .

ledvinam commented 4 years ago

So there has to be a way to get to those already oppened ports when we open our app after crash. Does it make sense?

On Wed, Sep 18, 2019, 18:02 Marek Ledvina ledvina.m@gmail.com wrote:

We compile it into dll and use it in Unity. The issue is if our unity app crashes for whatever reason connected or not connected to rtmidi we simply are unable to close the ports.

On Wed, Sep 18, 2019, 18:00 Tobias Schlemmer notifications@github.com wrote:

@ledvinam https://github.com/ledvinam Is your source code public? Does your application crash due to an unhandled exception or because of some segmentation fault? In the former case you probably use new and delete for managing your object. In that case your should make shure that

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/thestk/rtmidi/issues/210?email_source=notifications&email_token=AHE4XIVEYSY2FVM54N4AT73QKIC35A5CNFSM4IXYJNW2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD67VTVQ#issuecomment-532634070, or mute the thread https://github.com/notifications/unsubscribe-auth/AHE4XIWXMKQKPDEL6CDL56LQKIC35ANCNFSM4IXYJNWQ .

keinstein commented 4 years ago

So there has to be a way to get to those already oppened ports when we open our app after crash. Does it make sense?

Not really. That is forbidden by the architecture. The first thing you should classify your crash. Only on segmentation faults/page faults/bus errors there may be some design decisions that enforce this behavior in MacOS. Otherwise your are still responsible to do proper error handling in your app.

ledvinam commented 4 years ago

Ok got it and understand.

On Wed, Sep 18, 2019, 18:08 Tobias Schlemmer notifications@github.com wrote:

So there has to be a way to get to those already oppened ports when we open our app after crash. Does it make sense?

Not really. That is forbidden by the architecture. The first thing you should classify your crash. Only on segmentation faults/page faults/bus errors there may be some design decisions that enforce this behavior in MacOS. Otherwise your are still responsible to do proper error handling in your app.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/thestk/rtmidi/issues/210?email_source=notifications&email_token=AHE4XIQZ2CXV4TT2224HCQDQKID3HA5CNFSM4IXYJNW2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD67WH5A#issuecomment-532636660, or mute the thread https://github.com/notifications/unsubscribe-auth/AHE4XIXDJZTAPPAWV5MSKVLQKID3HANCNFSM4IXYJNWQ .