Skip to content

Commit d29036e

Browse files
committed
src: support sync 'overlapped' stdio option
Fix an oversight in the pull request that introduced the 'overlapped' option to the asynchronous child process methods, and also add it to the synchronous methods, like child_process.spawnSync(). Fixes: nodejs#48476 Refs: nodejs#29412
1 parent 0d725d6 commit d29036e

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

src/spawn_sync.cc

+19-3
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,12 @@ void SyncProcessOutputBuffer::set_next(SyncProcessOutputBuffer* next) {
9595
SyncProcessStdioPipe::SyncProcessStdioPipe(SyncProcessRunner* process_handler,
9696
bool readable,
9797
bool writable,
98+
bool overlapped,
9899
uv_buf_t input_buffer)
99100
: process_handler_(process_handler),
100101
readable_(readable),
101102
writable_(writable),
103+
overlapped_(overlapped),
102104
input_buffer_(input_buffer),
103105

104106
first_output_buffer_(nullptr),
@@ -202,6 +204,11 @@ bool SyncProcessStdioPipe::writable() const {
202204
}
203205

204206

207+
bool SyncProcessStdioPipe::overlapped() const {
208+
return overlapped_;
209+
}
210+
211+
205212
uv_stdio_flags SyncProcessStdioPipe::uv_flags() const {
206213
unsigned int flags;
207214

@@ -210,6 +217,8 @@ uv_stdio_flags SyncProcessStdioPipe::uv_flags() const {
210217
flags |= UV_READABLE_PIPE;
211218
if (writable())
212219
flags |= UV_WRITABLE_PIPE;
220+
if (overlapped())
221+
flags |= UV_OVERLAPPED_PIPE;
213222

214223
return static_cast<uv_stdio_flags>(flags);
215224
}
@@ -897,7 +906,8 @@ int SyncProcessRunner::ParseStdioOption(int child_fd,
897906
if (js_type->StrictEquals(env()->ignore_string())) {
898907
return AddStdioIgnore(child_fd);
899908

900-
} else if (js_type->StrictEquals(env()->pipe_string())) {
909+
} else if (js_type->StrictEquals(env()->pipe_string()) ||
910+
js_type->StrictEquals(env()->overlapped_string())) {
901911
Isolate* isolate = env()->isolate();
902912
Local<String> rs = env()->readable_string();
903913
Local<String> ws = env()->writable_string();
@@ -924,7 +934,8 @@ int SyncProcessRunner::ParseStdioOption(int child_fd,
924934
}
925935
}
926936

927-
return AddStdioPipe(child_fd, readable, writable, buf);
937+
bool overlapped = js_type->StrictEquals(env()->overlapped_string());
938+
return AddStdioPipe(child_fd, readable, writable, overlapped, buf);
928939

929940
} else if (js_type->StrictEquals(env()->inherit_string()) ||
930941
js_type->StrictEquals(env()->fd_string())) {
@@ -951,12 +962,17 @@ int SyncProcessRunner::AddStdioIgnore(uint32_t child_fd) {
951962
int SyncProcessRunner::AddStdioPipe(uint32_t child_fd,
952963
bool readable,
953964
bool writable,
965+
bool overlapped,
954966
uv_buf_t input_buffer) {
955967
CHECK_LT(child_fd, stdio_count_);
956968
CHECK(!stdio_pipes_[child_fd]);
957969

958970
std::unique_ptr<SyncProcessStdioPipe> h(
959-
new SyncProcessStdioPipe(this, readable, writable, input_buffer));
971+
new SyncProcessStdioPipe(this,
972+
readable,
973+
writable,
974+
overlapped,
975+
input_buffer));
960976

961977
int r = h->Initialize(uv_loop_);
962978
if (r < 0) {

src/spawn_sync.h

+4
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class SyncProcessStdioPipe {
7676
SyncProcessStdioPipe(SyncProcessRunner* process_handler,
7777
bool readable,
7878
bool writable,
79+
bool overlapped,
7980
uv_buf_t input_buffer);
8081
~SyncProcessStdioPipe();
8182

@@ -87,6 +88,7 @@ class SyncProcessStdioPipe {
8788

8889
inline bool readable() const;
8990
inline bool writable() const;
91+
inline bool overlapped() const;
9092
inline uv_stdio_flags uv_flags() const;
9193

9294
inline uv_pipe_t* uv_pipe() const;
@@ -119,6 +121,7 @@ class SyncProcessStdioPipe {
119121

120122
bool readable_;
121123
bool writable_;
124+
bool overlapped_;
122125
uv_buf_t input_buffer_;
123126

124127
SyncProcessOutputBuffer* first_output_buffer_;
@@ -182,6 +185,7 @@ class SyncProcessRunner {
182185
inline int AddStdioPipe(uint32_t child_fd,
183186
bool readable,
184187
bool writable,
188+
bool overlapped,
185189
uv_buf_t input_buffer);
186190
inline int AddStdioInheritFD(uint32_t child_fd, int inherit_fd);
187191

test/parallel/test-child-process-stdio-overlapped.js

+11
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ if (!require('fs').existsSync(exePath)) {
3737
common.skip(exe + ' binary is not available');
3838
}
3939

40+
// We can't synchronously write to the child (the 'input' and 'stdio' options
41+
// conflict) but we can at least verify it starts up normally and is then
42+
// terminated by the timer watchdog.
43+
const { error } = child_process.spawnSync(exePath, [], {
44+
stdio: ['overlapped', 'pipe', 'pipe'],
45+
timeout: 42,
46+
});
47+
48+
assert.ok(error);
49+
assert.strictEqual(error.code, 'ETIMEDOUT');
50+
4051
const child = child_process.spawn(exePath, [], {
4152
stdio: ['overlapped', 'pipe', 'pipe']
4253
});

0 commit comments

Comments
 (0)