bugGNU Octave - Bugs: bug #58678, Deadlock when deleting a figure...


bug #58678: Deadlock when deleting a figure while another figure is beingdeleted

Submitter:  Pantxo Diribarne <pantxo>
Submitted:  Mon 29 Jun 2020 08:27:19 PM UTC
Category:  Plotting with OpenGL Severity:  4 - Important
Priority:  5 - Normal Item Group:  Segfault, Bus Error, etc.
Status:  Confirmed Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup

Jump to the original submission

Fri 09 Feb 2024 07:07:15 PM UTC, comment #6: 

changeset:   32995:7f47ba772a19
branch:      stable
parent:      32992:88bff22985bd
user:        Markus Mützel <markus.muetzel@gmx.de>
date:        Fri Feb 09 18:33:49 2024 +0100
summary:     filter: Add small tolerance to BIST with floating point input.

Attached thread sanitizer trace. Not sure how useful it could be.


(file #55682)

Dmitri A. Sergatskov <dasergatskov>
Fri 09 Feb 2024 06:40:47 PM UTC, comment #5: 
Dmitri A. Sergatskov <dasergatskov>
Fri 09 Feb 2024 05:44:47 PM UTC, comment #4: 

This still deadlocks in Octave 9.0.90 with the following commands:

hf = figure ();
hf2 = figure ();
addlistener (hf, "beingdeleted", @(h,e) delete (hf2));
delete (hf);

Markus Mützel <mmuetzel>
Group administrator
Tue 11 Jul 2023 02:28:04 AM UTC, comment #3: 

It does not lock for me in 9.0:

octave:1> hf = figure ();
hf2 = figure ();
addlistener (hf, "beingdeleted", @() delete (hf2));
delete (hf);
error: @<anonymous>: function called with too many inputs
error: called from
    delete at line 73 column 5
octave:5> version -hgid
ans = 37e184a83cf4


Dmitri A. Sergatskov <dasergatskov>
Wed 19 Aug 2020 08:46:04 PM UTC, comment #2: 

@Markus: This possible deadlock has been present for one release cycle now and had not been reported yet. It looks like those recursive patterns are not very likely to happen, so I'd also vote for making this a high priority but not a blocker.

>> That probably also means that we can lock (and unlock) recursively on Windows (which is a good thing iiuc).

Yes this means that linux and windows implementations are consistent (and both different from what I had expected when I introduced this bug).

Pantxo Diribarne <pantxo>
Group Member
Wed 19 Aug 2020 04:34:21 PM UTC, comment #1: 

I can confirm that the deadlock still happens in current Octave 6.0.1 stable (hg id d075c2f26d1d).

It looks like it also deadlock in Octave 5.2.0 (on Windows). So this is not a regression.
That probably also means that we can lock (and unlock) recursively on Windows (which is a good thing iiuc).

Should this block the release in that case? (I'd guess it shouldn't.)

Markus Mützel <mmuetzel>
Group administrator
Mon 29 Jun 2020 08:27:19 PM UTC, original submission:  

Here is a robust way to deadlock with Octave 5.1, stable and default:

hf = figure ();
hf2 = figure ();
addlistener (hf, "beingdeleted", @() delete (hf2));
delete (hf);

I dug into this and it turns out that this sequence provokes a recursive call to F__go_delete__. This function uses an octave::autolock to lock the graphics mutex and then unlock it at return. When graphics_toolkit::finalize is called, the graphics mutex has been locked twice and using gh_manager::unlock is not enough to unlock it (unlocking twice avoids the deadlock).

IOW, I just discovered that octave_mutex is a recursive mutex, and there is no way to unlock it unless you know the number of times it has been previously locked in the same thread. See also [1] for a discussion about recursive mutexes.

So both qt_graphics_toolkit::initialize and finalize, can possibly deadlock.

PS: Contrary to what I have said in [2], our implementation of mutex is thus very well suited for recursive use with octave::autolock.

PPS: I tagged this bug as segfault since a deadlock looks as critical.
[1] http://www.zaval.org/resources/library/butenhof1.html
[2] https://octave.1599824.n4.nabble.com/segfaults-in-graphics-code-likely-threading-issues-td4697518.html

Pantxo Diribarne <pantxo>
Group Member


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

Attach Files:

Attached Files


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by dasergatskov (Posted a comment)
  • -email is unavailable- added by mmuetzel (Posted a comment)
  • -email is unavailable- added by pantxo (Submitted the item)

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.


    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2024-02-09 dasergatskov Attached File- Added tsan_7f47ba772a19_lock.txt.gz, #55682
    2020-08-19 mmuetzel Operating SystemGNU/Linux Any

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code