DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 59MHMaSi1763845 Authentication-Results: delorie.com; dmarc=pass (p=none dis=none) header.from=cygwin.com Authentication-Results: delorie.com; spf=pass smtp.mailfrom=cygwin.com DKIM-Filter: OpenDKIM Filter v2.11.0 delorie.com 59MHMaSi1763845 Authentication-Results: delorie.com; dkim=pass (1024-bit key, unprotected) header.d=cygwin.com header.i=@cygwin.com header.a=rsa-sha256 header.s=default header.b=aSe8DJyo X-Recipient: archive-cygwin AT delorie DOT com DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3973C385841D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; s=default; t=1761153754; bh=Jz1o6Fyf8p2VtDm4yqAITjATHskPBnKrx4BD34bADvw=; h=References:In-Reply-To:Date:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=aSe8DJyovITrb3PfXU1B/2zo6FHJ0gwOI+77VAEEsWItn1tKgPmN4iLTA19M+sKBd W2uxRjj5EoXf8PBcn16Qwxl+zNAFhaqDa9WQVD/qyf/qhoKP6QW1FnBtLtLq0g3VLQ 8HEfjcRUFaG+PhH9lzyrEjeOi/pfqxbh0GT/eHqE= X-Original-To: cygwin AT cygwin DOT com Delivered-To: cygwin AT cygwin DOT com DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1A30A385842B ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1A30A385842B ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1761153682; cv=none; b=rgKpADZtnzEuwWUmuJt0r1+NFIQJ2TgbosO7z7gmDPynBS30U68nCpqDvjuhiI+TTIiGz/WIfks8tbgeqvtJNm6JQDY4jzfbReamarojKy4EhW/QWvDxQy5hMnnIogcfZCue6Yq+qMJ9IeuhIjDVQnt4wmFjC/aDFbe36ag5Vgc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1761153682; c=relaxed/simple; bh=95rXOZh4HdPDVrHOn5F1PNtFTNB8od7ELiDoKZIZDek=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=RuyvgT/AMANuSTGgByjXJBLsmKJjwBxQcnmUfFSUlAq4Dx5B5nKYQcBEupyWqeahS3ANzdFyJTzxTd6KWgB1y+cwK9qQjfeD+hcAIcFcc1YQPRhUzAbzCyKDZnYwpfkS/9n7fKT/bMAnP9CrItLgxdaYU8XeOgr+ATnsFe0/Wos= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1A30A385842B X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761153681; x=1761758481; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5wEaU2fcuLvaf+golkpK1BGeZuDGtu9V6fws6tC5g+Y=; b=dR6GjFjdObMXk2ogc/RdNDY9SdBg478ClEppZ1XO2dxF8Cw8JR9GwURXA+8r15j/g+ 64WITWrE5mBq015QFrk8sLsLTzATtFh4z1GzSbqIILd4xFe79KgvxQ1fSJci8BVX1Vhg 4uGdbwhMpUFpiQGIoXmGCdmK5jdbJ5g84LmKdVszuWlGTkfMZpeqnH5Hw8J8noZwIgeR eh70/GwM7paARexGY6atTr3SMuPFWnsYcbmUaNFtxTLH6hgTCCMUXVzgCMxs/jFLJ7v8 vMAfGGwBvZxLg392KR0DmiPkQi9p53w4brHU/7c5qwQL7g6OPcAVUjjKfFIACdU8dPYq 5PLQ== X-Gm-Message-State: AOJu0Yy4HKERbZD/0KStTKxbd/jhrezdqhYoHb1udJSjQR7uS3ZfGs0F VODXBAeD92b33tCU4q0QJg1L48Xo9UjTKYlfKeEudh0kUJgU+07i+zIs9FGgBqeAUcqrHfqplaL fkBTXVEhrvjSM2f519mZfiMH4vx/xKgLm X-Gm-Gg: ASbGnctmSy6l3YR0Dwp1uoxMBsGtefNro0eiAGdiVQgQMa5+FhvaDORumB5KvE5lLHL ttYQjbmKdn0tbiB3rxnyvTCWeGMnj+eRTSWqzHkX/4PyoLmKrL48T56+9mS+sRa+vhnV1p6bwG7 ZAbCdMDrnlBNoDVhWd8L81WbOZGyLBoCW0PgqwFX3LDAK9oT+cQMA3i2nSpPui6U1ufSWR1Xh7R +RJAmNgayfgC2KPca0dWcwgRxvWcmvdJ4Jwt/cGMP4SmXlm/rIIMOljFHGWApH4mQPPfaR+nliI b7osclGlXYZYAKkzx2qNijQNTw== X-Google-Smtp-Source: AGHT+IEcy/xoR41KNr0NgImUwL6ctuDHFpUHaiPxi2/pDVERIIZZ7JoBodnEYzxd0Fuavbe0F46STE8CXKa2Ogq8b/o= X-Received: by 2002:a05:690e:1583:20b0:63d:2163:24dc with SMTP id 956f58d0204a3-63ea1b619d6mr3259096d50.8.1761153681152; Wed, 22 Oct 2025 10:21:21 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 22 Oct 2025 10:21:10 -0700 X-Gm-Features: AS18NWDsXywoPh1FWBoK4ocF8kV9KrDGEruEJ2j5GnAPY5unyht6o1tDpxlFyuM Message-ID: Subject: Re: flock/open random error To: cygwin AT cygwin DOT com X-BeenThere: cygwin AT cygwin DOT com X-Mailman-Version: 2.1.30 List-Id: General Cygwin discussions and problem reports List-Archive: List-Post: List-Help: List-Subscribe: , From: Nahor via Cygwin Reply-To: Nahor Content-Type: text/plain; charset="utf-8" Sender: "Cygwin" Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 59MHMaSi1763845 Small simplification and generalization of the issue: The location of the directory and the file in relation to each other is irrelevant. I can still reproduce the issue with the directory being on one drive and the file on another. The flock error ("Bad addr") didn't happen in some variations (e.g. directory on C drive and file on D drive), but given how rare the error is to begin with, I assume it's only a timing issue (my D drive is older than my C for instance) On Tue, Oct 21, 2025 at 5:41 PM Nahor wrote: > > Hi, > > There is a test in the Fish shell (tests::history::test_history_races) > that systematically fails when I run it. The test simulates multiple > processes/threads trying to write to the shell history file at the > same time. > In my case, the test freezes/deadlocks with errors like "Bad Addr" and > "Is Directory". > When I add a sleep, the freeze/deadlocks disappear but the test > eventually fails because the fake history is not the right size. > See https://github.com/fish-shell/fish-shell/issues/11933 for more details. > > I wrote a test case in pure C (attached) that also triggers the issue > although it's not as systematic (30-50%). > To compile: gcc main.c -o test.exe > To run: ./test.exe > > > Most failures look like this: > ``` > $ ./test.exe > tmp_dir: /tmp/flockc2Hz4c > open file error: 21 - Is a directory > /tmp/flockc2Hz4c/append_file > assertion "file_fd >= 0" failed: file "main.c", line 49, function: > thread_func > Aborted > ``` > Occasionally (maybe 10%), it looks like that: > ``` > $ ./test.exe > tmp_dir: /tmp/flock5Oly9J > lock error: 14 - Bad address > assertion "lock_res == 0" failed: file "main.c", line 38, > function: thread_func > Aborted > ``` > > I believe the freeze/deadlock in the Fish test is because, unlike my > test, they don't assert/crash, and the next time they access the > history file, there is a bunch of deadlock in cygwin internals. > If that helps, this is a partial capture of the stack traces at one such time: > ``` > Thread 9 > #2 0x00000001800d487f in muto::acquire (this=0x1802c24c0 > , ms=ms AT entry=4294967295) at > /d/S/B/src/msys2-runtime/winsup/cygwin/sync.cc:84 > #3 0x00000001800dd6e0 in dtable::lock (this=) at > /d/S/B/src/msys2-runtime/winsup/cygwin/local_includes/dtable.h:77 > #4 cygheap_fdnew::cygheap_fdnew (this=, > seed_fd=-1, lockit=true) at > /d/S/B/src/msys2-runtime/winsup/cygwin/local_includes/cygheap.h:593 > #5 open (unix_path=0xa0002b3b0 > "[...]/fish-shell/target/fish-test-home", flags=262144) at > /d/S/B/src/msys2-runtime/winsup/cygwin/syscalls.cc:1576 > > Thread 10 > #2 0x00000001800d487f in muto::acquire (this=0x1802c24c0 > , ms=ms AT entry=4294967295) at > /d/S/B/src/msys2-runtime/winsup/cygwin/sync.cc:84 > #3 0x00000001800dd6e0 in dtable::lock (this=) at > /d/S/B/src/msys2-runtime/winsup/cygwin/local_includes/dtable.h:77 > #4 cygheap_fdnew::cygheap_fdnew (this=, > seed_fd=-1, lockit=true) at > /d/S/B/src/msys2-runtime/winsup/cygwin/local_includes/cygheap.h:593 > #5 open (unix_path=0xa0002bfe0 > "[...]/fish-shell/target/fish-test-home/race_test_history.FwyAgK", > flags=264706) at > /d/S/B/src/msys2-runtime/winsup/cygwin/syscalls.cc:1576 > > Thread 11 > #2 0x00000001800670bb in inode_t::LOCK (this=0x80000ba20) at > /d/S/B/src/msys2-runtime/winsup/cygwin/flock.cc:314 > #3 inode_t::get (dev=1881899537, ino=ino AT entry=10977524092162599, > create_if_missing=create_if_missing AT entry=false, lock=lock AT entry=true) > at /d/S/B/src/msys2-runtime/winsup/cygwin/flock.cc:504 > #4 0x0000000180068eb1 in fhandler_base::del_my_locks > (this=0x80000b810, from=on_close) at > /d/S/B/src/msys2-runtime/winsup/cygwin/flock.cc:402 > #5 0x000000018010d5bf in fhandler_base::close_with_arch > (this=0x80000b810, flag=flag AT entry=-1) at > /d/S/B/src/msys2-runtime/winsup/cygwin/fhandler/base.cc:1306 > #6 0x00000001800de36b in __close (fd=5, flag=-1) at > /d/S/B/src/msys2-runtime/winsup/cygwin/syscalls.cc:1710 > #7 close (fd=5) at /d/S/B/src/msys2-runtime/winsup/cygwin/syscalls.cc:1722 > > Thread 12 > #2 0x00000001800d487f in muto::acquire (this=0x1802c24c0 > , ms=ms AT entry=4294967295) at > /d/S/B/src/msys2-runtime/winsup/cygwin/sync.cc:84 > #3 0x00000001800dd6e0 in dtable::lock (this=) at > /d/S/B/src/msys2-runtime/winsup/cygwin/local_includes/dtable.h:77 > #4 cygheap_fdnew::cygheap_fdnew (this=, > seed_fd=-1, lockit=true) at > /d/S/B/src/msys2-runtime/winsup/cygwin/local_includes/cygheap.h:593 > #5 open (unix_path=0x7ff10b488 > "[...]/fish-shell/target/fish-test-home/race_test_history.pZO5DS", > flags=263169) at > /d/S/B/src/msys2-runtime/winsup/cygwin/syscalls.cc:1576 > ``` > The freeze/deadlock can be reproduced in my C code by calling > "continue" inside the "if (lock_res != 0) {" instead of triggering the > assert just after. > > > I haven't been able to reproduce the missing data in the history file > so it's unknown if it's an issue in Fish or flock not locking properly > at times. So far the test passes on Linux and MacOS. > > > Thanks, > Nahor -- Problem reports: https://cygwin.com/problems.html FAQ: https://cygwin.com/faq/ Documentation: https://cygwin.com/docs.html Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple