Skip to content

Commit 994ead5

Browse files
committed
ignore SIGPIPE
1 parent 62f5da9 commit 994ead5

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

src/internal/event_loop/thread_pool.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,12 @@ void moonbitlang_async_init_thread_pool(int notify_send) {
175175
pthread_sigmask(SIG_BLOCK, &pool.wakeup_signal, &pool.old_sigmask);
176176
#endif
177177

178-
sigset_t sigpipe;
179-
sigemptyset(&sigpipe);
180-
sigaddset(&sigpipe, SIGPIPE);
181-
sigaddset(&sigpipe, SIGCHLD);
182-
pthread_sigmask(SIG_BLOCK, &sigpipe, 0);
178+
sigset_t signals_to_block;
179+
sigemptyset(&signals_to_block);
180+
sigaddset(&signals_to_block, SIGCHLD);
181+
pthread_sigmask(SIG_BLOCK, &signals_to_block, 0);
182+
183+
signal(SIGPIPE, SIG_IGN);
183184

184185
pool.notify_send = notify_send;
185186
pool.initialized = 1;

src/pipe/moon.pkg.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"targets": {
1111
"ffi.mbt": [ "native" ],
1212
"pipe.mbt": [ "native" ],
13-
"read_exactly_test.mbt": [ "native" ]
13+
"read_exactly_test.mbt": [ "native" ],
14+
"reader_closed_test.mbt": [ "native" ]
1415
}
1516
}

src/pipe/reader_closed_test.mbt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2025 International Digital Economy Academy
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
///|
16+
async test "reader closed" {
17+
let (r, w) = @pipe.pipe()
18+
r.close()
19+
@async.sleep(100)
20+
assert_true((try? w.write("abcd")) is Err(_))
21+
}

0 commit comments

Comments
 (0)