bugGNU Octave - Bugs: bug #52996, calling audiodevinfo() results in...

 
 

bug #52996: calling audiodevinfo() results in a segfault on exit when JACK sound server is running

Submitted by:  None
Submitted on:  Sun 28 Jan 2018 07:26:37 PM UTC  
 
Category:  Octave Function Severity:  4 - Important
Priority:  5 - Normal Item Group:  Segfault, Bus Error, etc.
Status:  Confirmed Assigned to:  None
Originator Name:  Marc Originator Email:  -email is unavailable-
Open/Closed:  Open Release:  4.2.1
Operating System:  GNU/Linux

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

( Jump to the original submission)

Fri 09 Mar 2018 06:41:22 PM UTC, comment #17:

I think the interpreter object is only needed for the call to mlock. That's the only reason I turned these functions into DEFMETHODs. So it should be pretty easy to backport onto stable.

Mike Miller <mtmiller>
Project Administrator
Fri 09 Mar 2018 06:40:24 PM UTC, comment #16:

I was going to look into trying to keep track of object instances so that the oct file can be unlocked and unloaded when all players and recorders are cleaned up. But I can certainly push what I have so far as a first level improvement. It just means the audiodevinfo oct file will never be unloaded after any of the functions are called once.

This could be backported to stable if needed to avoid the crash, but I wonder how few Octave users are also JACK users.

Mike Miller <mtmiller>
Project Administrator
Fri 09 Mar 2018 04:38:03 PM UTC, comment #15:

Mike: Do you want to add a commit message and push? Since this patch uses the new interpreter object, I guess it will just apply to default. That's OK with me.

John W. Eaton <jwe>
Project Administrator
Thu 15 Feb 2018 08:53:50 PM UTC, comment #14:

Nevermind, it does work, probably because the internal C++ classes are registered octave_values, so when the m-file class is cleared, its reference to the player/recorder object is deleted properly. Doesn't need a classdef destructor in this case.

So I'll look into keeping a count of those internal objects and unlocking when possible.

Mike Miller <mtmiller>
Project Administrator
Thu 15 Feb 2018 08:47:44 PM UTC, comment #13:

Yeah, it's a reasonable thing to do for now.

John W. Eaton <jwe>
Project Administrator
Thu 15 Feb 2018 08:45:36 PM UTC, comment #12:

In the meantime, I think this change could be pushed then, it doesn't make the situation any worse, right? It just prevents the audio functions from ever being unloaded after audiodevinfo or audioplayer or audiorecorder are called once. Avoids segfaults in various ways. I'll file another bug for never cleaning up any audio objects.

Mike Miller <mtmiller>
Project Administrator
Thu 15 Feb 2018 08:43:49 PM UTC, comment #11:

Wow, I just noticed that we don't delete the heap-allocated player and recorder objects at all. So yes, we need classdef destructors working first, then we can reliably delete instances, and then we can actually unload the functions when all instances are deleted.

Mike Miller <mtmiller>
Project Administrator
Thu 15 Feb 2018 05:29:32 AM UTC, comment #10:

The class to manage the calls to load/unload PortAudio seem fine.

I'm not sure what to do about unlocking when the last object is deleted. If you were using classdef and if classdef destructors worked properly, then I think you could use reference counting to do this job.

John W. Eaton <jwe>
Project Administrator
Thu 15 Feb 2018 12:26:15 AM UTC, comment #9:

I have a work in progress, diff attached.

jwe - would you mind taking a look at this? There are two changes, first adding a static sentry object to make sure PortAudio is only initialized once, and uninitialized at unload or exit. That part is simple and works.

The second change is to mlock whichever function calls Pa_Initialize the first time, to avoid bad things happening with something like

But I have no known point at which I can call munlock. Should we add object tracking so that we can safely munlock and allow these functions to be unloaded if all corresponding audio objects have been cleared?

(file #43327)

Mike Miller <mtmiller>
Project Administrator
Sun 11 Feb 2018 08:06:48 PM UTC, comment #8:

The audiodevinfo oct file needs a call to Pa_Terminate when it is unloaded to safely deinitialize the jack library connection.

Mike Miller <mtmiller>
Project Administrator
Sun 11 Feb 2018 06:56:54 PM UTC, comment #7:

Yes, the proposed commands also result in a segmentation fault for me.

However, here it crashed with "-p 1024" as well as with "-p 2048" and "-p 512".

Anonymous
Fri 09 Feb 2018 12:55:45 AM UTC, comment #6:

I can reproduce this crash now with the following

The crash occurs on "clear functions", when the audiodevinfo oct file is unloaded, and recursively the portaudio and jack libraries are unloaded.

This crash only occurs for me when the jack server is started with "-p 512" or a lower number. With the default "-p 1024" or a higher value the crash does not occur.

Can you verify those findings?

Btw if you are using octave-cli, you can use gdb with just "gdb --args octave-cli" with whatever options and arguments following that.

But I'm not able to get a very useful backtrace from gdb. I think this is because the error is related to the jack library creating threads in the background and then octave unloading the portaudio library while these threads are still active.

Mike Miller <mtmiller>
Project Administrator
Thu 08 Feb 2018 10:02:46 AM UTC, comment #5:

At first I thought Octave would always crash, but it does not.
But I cannot find a consistent pattern.

Sometimes it crashes, sometimes it does not.
It seems to crash more often with the USB device than with the dummy device.
And it seems to crash more often when starting octave-cli manually, then type "audiodevinfo" and then "exit" (instead of running "octave-cli --eval 'audiodevinfo'"

I manually installed the octave and liboctave ddeb files.
I was not able to produce a stack trace: When I start GDB from within octave-cli

> system (sprintf ("gnome-terminal --command 'gdb -p %d'", getpid ()), "async");

I cannot type in the octave terminal anymore.
Last words of GDB here are:

Reading symbols from /usr/lib/x86_64-linux-gnu/octave/4.2.1/oct/x86_64-pc-linux-gnu/__init_gnuplot__.oct...Reading symbols from /usr/lib/debug/.build-id/fc/0ba7125263e7e95eab390a739e3604f6faf553.debug...done.
done.
0x00007fc3eacb99cc in __pselect (nfds=1, readfds=0x7ffdfe176420, writefds=0x0,
exceptfds=0x0, timeout=<optimized out>, sigmask=<optimized out>)
at ../sysdeps/unix/sysv/linux/pselect.c:69
69 ../sysdeps/unix/sysv/linux/pselect.c: Datei oder Verzeichnis nicht gefunden.
(gdb)

However, I achieved to run and crash the octave with valgrind (output attached).
Maybe the output already helps.

Best,
Marc

(file #43205)

Anonymous
Sat 03 Feb 2018 02:40:26 AM UTC, comment #4:

Can you try changing some options and let us know if they also crash for you?

For example try

  • starting jackd with -d dummy instead of -d alsa
  • starting jackd with the -r or --no-realtime option

Since you are using Ubuntu, you should be able to install debug symbol packages (https://wiki.ubuntu.com/Debug%20Symbol%20Packages) and use gdb to share a stack trace at the point of the crash on your system (https://wiki.octave.org/Debugging_Octave).

Mike Miller <mtmiller>
Project Administrator
Thu 01 Feb 2018 06:34:57 PM UTC, comment #3:

This works for me.

Mike Miller <mtmiller>
Project Administrator
Thu 01 Feb 2018 08:00:34 AM UTC, comment #2:

Hi Mike!

I am happy to provide some more information.
Building octave is beyond what I can do atm.

Linux kernel
marc@bullsquid:~$ uname -a
Linux bullsquid 4.13.0-32-generic #35-Ubuntu SMP Thu Jan 25 09:13:46 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

Ubuntu version
marc@bullsquid:~$ lsb_release -d
Description: Ubuntu 17.10

JACK version
marc@bullsquid:~$ jackd --version
jackdmp 1.9.11
...
jackdmp version 1.9.11 tmpdir /dev/shm protocol 8

Octave version
marc@bullsquid:~$ octave --version
GNU Octave, version 4.2.1

Soundcards
marc@bullsquid:~$ aplay -l

        • Liste der Hardware-Geräte (PLAYBACK) ****

Karte 0: NVidia [HDA NVidia], Gerät 3: HDMI 0 [HDMI 0]
Sub-Geräte: 1/1
Sub-Gerät #0: subdevice #0
Karte 0: NVidia [HDA NVidia], Gerät 7: HDMI 1 [HDMI 1]
Sub-Geräte: 1/1
Sub-Gerät #0: subdevice #0
Karte 1: USB [Scarlett 2i2 USB], Gerät 0: USB Audio [USB Audio]
Sub-Geräte: 1/1
Sub-Gerät #0: subdevice #0

My user is member of the "audio" group on that system.

To reproduce run

> jackd -d alsa -d hw:USB -p 512 -r 48000 -n 10 & sleep 3 && octave-cli --eval "audiodevinfo();" || echo '!!! BUG BUG BUG !!!'


This starts jackd in background, waits 3 seconds and then runs audiodevinfo() with Octave (which segfaults)

My output WITH jack running:
marc@bullsquid:~$ jackd -d alsa -d hw:USB -p 512 -r 48000 -n 10 & sleep 3 && octave-cli --eval "audiodevinfo();" || echo '!!! BUG BUG BUG !!!'
[1] 14880
jackdmp 1.9.11
Copyright 2001-2005 Paul Davis and others.
Copyright 2004-2014 Grame.
jackdmp comes with ABSOLUTELY NO WARRANTY
This is free software, and you are welcome to redistribute it
under certain conditions; see the file COPYING for details
no message buffer overruns
no message buffer overruns
no message buffer overruns
JACK server starting in realtime mode with priority 10
self-connect-mode is "Don't restrict self connect requests"
audio_reservation_init
Acquire audio card Audio1
creating alsa driver ... hw:USB|hw:USB|512|10|48000|0|0|nomon|swmeter|-|32bit
configuring for 48000Hz, period = 512 frames (10.7 ms), buffer = 10 periods
ALSA: final selected sample format for capture: 32bit integer little-endian
ALSA: use 10 periods for capture
ALSA: final selected sample format for playback: 32bit integer little-endian
ALSA: use 10 periods for playback
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dmix.c:1052:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_dmix.c:1052:(snd_pcm_dmix_open) unable to open slave
panic: Segmentation fault -- stopping myself...panic: attempted clean up failed -- aborting...

JackEngine::XRun: client = PortAudio was not finished, state = Triggered
JackAudioDriver::ProcessGraphAsyncMaster: Process error
JackEngine::XRun: client = PortAudio was not finished, state = Triggered
JackAudioDriver::ProcessGraphAsyncMaster: Process error
JackEngine::XRun: client = PortAudio was not finished, state = Triggered
JackAudioDriver::ProcessGraphAsyncMaster: Process error
JackEngine::XRun: client = PortAudio was not finished, state = Triggered
JackAudioDriver::ProcessGraphAsyncMaster: Process error
JackEngine::XRun: client = PortAudio was not finished, state = Triggered
JackAudioDriver::ProcessGraphAsyncMaster: Process error
JackEngine::XRun: client = PortAudio was not finished, state = Triggered
JackAudioDriver::ProcessGraphAsyncMaster: Process error
JackEngine::XRun: client = PortAudio was not finished, state = Triggered
JackAudioDriver::ProcessGraphAsyncMaster: Process error
JackEngine::XRun: client = PortAudio was not finished, state = Triggered
JackAudioDriver::ProcessGraphAsyncMaster: Process error
JackEngine::XRun: client = PortAudio was not finished, state = Triggered
JackAudioDriver::ProcessGraphAsyncMaster: Process error
JackEngine::XRun: client = PortAudio was not finished, state = Triggered
JackAudioDriver::ProcessGraphAsyncMaster: Process error
JackEngine::XRun: client = PortAudio was not finished, state = Triggered
JackAudioDriver::ProcessGraphAsyncMaster: Process error
JackEngine::XRun: client = PortAudio was not finished, state = Triggered
JackAudioDriver::ProcessGraphAsyncMaster: Process error
Cannot read socket fd = 11 err = Connection reset by peer
Could not read notification result
ClientNotify fails name = PortAudio notification = 18 val1 = 0 val2 = 0
Cannot write socket fd = 11 err = Broken pipe
CheckRes error
Could not write notification
ClientNotify fails name = PortAudio notification = 18 val1 = 1 val2 = 0
Cannot write socket fd = 11 err = Broken pipe
CheckRes error
Could not write notification
ClientNotify fails name = PortAudio notification = 3 val1 = 0 val2 = 0
Abgebrochen (Speicherabzug geschrieben)
!!! BUG BUG BUG !!!

My output WITHOUT jack running:

> marc@bullsquid:~$ octave-cli --eval "audiodevinfo();" || echo '!!! BUG BUG BUG !!!'

ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dmix.c:1052:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_dmix.c:1052:(snd_pcm_dmix_open) unable to open slave
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for 4294967295, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for 4294967295, skipping unlock

Anonymous
Thu 01 Feb 2018 01:32:07 AM UTC, comment #1:

Please provide some more information about how to reproduce this, and preferably a debug stack trace with gdb if you are able (https://wiki.octave.org/Debugging_Octave). A similar bug was reported previously by a Debian user (see https://bugs.debian.org/874208), but I was unable to reproduce the crash with either jackd1 or jackd2.

Mike Miller <mtmiller>
Project Administrator
Sun 28 Jan 2018 07:26:37 PM UTC, original submission:

When the JACK server is running Octave produces a segfault on exit when "audiodevinfo()" was called before.

Tested with different sound cards (PCI and USB).
It does not crash when JACK is not running.

Best observed with octave-cli where the error message appears in the terminal:

octave:1> A=audiodevinfo;
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dmix.c:1052:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_dmix.c:1052:(snd_pcm_dmix_open) unable to open slave
octave:2> exit
panic: Segmentation fault -- stopping myself...
attempting to save variables to 'octave-workspace'...
save to 'octave-workspace' complete
Speicherzugriffsfehler (Speicherabzug geschrieben)

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #43327:  portaudio.diff added by mtmiller (5KiB - application/octet-stream)
file #43205:  octave-crash-dbg-valgrind.txt added by None (38KiB - text/plain)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

     

     

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-02-15 mtmiller Severity3 - Normal => 4 - Important
    2018-02-15 mtmiller Attached File- => Added portaudio.diff, #43327
    2018-02-09 mtmiller StatusWorks For Me => Confirmed
    2018-02-08 None Attached File- => Added octave-crash-dbg-valgrind.txt, #43205
    2018-02-01 mtmiller StatusNeed Info => Works For Me
    2018-02-01 mtmiller StatusNone => Need Info

    Back to the top


    Powered by Savane 3.3