Skip to content

Commit 58a14f3

Browse files
committed
Revert "Merge pull request #17522 from JuliaLang/jn/reliable-flush-close"
This reverts commit 08ae28a, reversing changes made to 1eeb773. This is causing spawn test failures on Windows.
1 parent dea672c commit 58a14f3

File tree

11 files changed

+34
-78
lines changed

11 files changed

+34
-78
lines changed

base/process.jl

+6-13
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ type Process <: AbstractPipe
289289
typemin(fieldtype(Process, :termsignal)),
290290
false, Condition(), false, Condition())
291291
finalizer(this, uvfinalize)
292-
return this
292+
this
293293
end
294294
end
295295
pipe_reader(p::Process) = p.out
@@ -325,12 +325,9 @@ function _jl_spawn(cmd, argv, loop::Ptr{Void}, pp::Process,
325325
end
326326

327327
function uvfinalize(proc::Process)
328-
if proc.handle != C_NULL
329-
disassociate_julia_struct(proc.handle)
330-
ccall(:jl_close_uv, Void, (Ptr{Void},), proc.handle)
331-
proc.handle = C_NULL
332-
end
333-
nothing
328+
proc.handle != C_NULL && ccall(:jl_close_uv, Void, (Ptr{Void},), proc.handle)
329+
disassociate_julia_struct(proc)
330+
proc.handle = C_NULL
334331
end
335332

336333
function uv_return_spawn(p::Ptr{Void}, exit_status::Int64, termsignal::Int32)
@@ -339,19 +336,15 @@ function uv_return_spawn(p::Ptr{Void}, exit_status::Int64, termsignal::Int32)
339336
proc = unsafe_pointer_to_objref(data)::Process
340337
proc.exitcode = exit_status
341338
proc.termsignal = termsignal
342-
if isa(proc.exitcb, Function)
343-
proc.exitcb(proc, exit_status, termsignal)
344-
end
339+
if isa(proc.exitcb, Function) proc.exitcb(proc, exit_status, termsignal) end
345340
ccall(:jl_close_uv, Void, (Ptr{Void},), proc.handle)
346341
notify(proc.exitnotify)
347342
nothing
348343
end
349344

350345
function _uv_hook_close(proc::Process)
351346
proc.handle = C_NULL
352-
if isa(proc.closecb, Function)
353-
proc.closecb(proc)
354-
end
347+
if isa(proc.closecb, Function) proc.closecb(proc) end
355348
notify(proc.closenotify)
356349
end
357350

base/socket.jl

+11-3
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ function TCPSocket()
281281
throw(UVError("failed to create tcp socket",err))
282282
end
283283
this.status = StatusInit
284-
return this
284+
this
285285
end
286286

287287
type TCPServer <: LibuvServer
@@ -312,7 +312,7 @@ function TCPServer()
312312
throw(UVError("failed to create tcp server",err))
313313
end
314314
this.status = StatusInit
315-
return this
315+
this
316316
end
317317

318318
isreadable(io::TCPSocket) = isopen(io) || nb_available(io) > 0
@@ -365,11 +365,19 @@ function UDPSocket()
365365
throw(UVError("failed to create udp socket",err))
366366
end
367367
this.status = StatusInit
368-
return this
368+
this
369369
end
370370

371371
show(io::IO, stream::UDPSocket) = print(io, typeof(stream), "(", uv_status_string(stream), ")")
372372

373+
function uvfinalize(uv::Union{TTY,PipeEndpoint,PipeServer,TCPServer,TCPSocket,UDPSocket})
374+
if (uv.status != StatusUninit && uv.status != StatusInit)
375+
close(uv)
376+
end
377+
disassociate_julia_struct(uv)
378+
uv.handle = C_NULL
379+
end
380+
373381
function _uv_hook_close(sock::UDPSocket)
374382
sock.handle = C_NULL
375383
sock.status = StatusClosed

base/stream.jl

+5-26
Original file line numberDiff line numberDiff line change
@@ -322,26 +322,9 @@ function wait_close(x::Union{LibuvStream, LibuvServer})
322322
end
323323

324324
function close(stream::Union{LibuvStream, LibuvServer})
325-
if isopen(stream)
326-
if stream.status != StatusClosing
327-
ccall(:jl_close_uv, Void, (Ptr{Void},), stream.handle)
328-
stream.status = StatusClosing
329-
end
330-
if uv_handle_data(stream) != C_NULL
331-
stream_wait(stream, stream.closenotify)
332-
end
333-
end
334-
nothing
335-
end
336-
337-
function uvfinalize(uv::Union{LibuvStream, LibuvServer})
338-
if uv.handle != C_NULL
339-
disassociate_julia_struct(uv.handle) # not going to call the usual close hooks
340-
if uv.status != StatusUninit && uv.status != StatusInit
341-
close(uv)
342-
uv.handle = C_NULL
343-
uv.status = StatusClosed
344-
end
325+
if isopen(stream) && stream.status != StatusClosing
326+
ccall(:jl_close_uv,Void, (Ptr{Void},), stream.handle)
327+
stream.status = StatusClosing
345328
end
346329
nothing
347330
end
@@ -489,10 +472,8 @@ function uv_readcb(handle::Ptr{Void}, nread::Cssize_t, buf::Ptr{Void})
489472
stream.status = StatusEOF # libuv called stop_reading already
490473
notify(stream.readnotify)
491474
notify(stream.closenotify)
492-
elseif stream.status != StatusClosing
493-
# begin shutdown of the stream
494-
ccall(:jl_close_uv, Void, (Ptr{Void},), stream.handle)
495-
stream.status = StatusClosing
475+
else
476+
close(stream)
496477
end
497478
else
498479
# This is a fatal connection error. Shutdown requests as per the usual
@@ -1038,8 +1019,6 @@ function close(s::BufferStream)
10381019
notify(s.close_c; all=true)
10391020
nothing
10401021
end
1041-
uvfinalize(s::BufferStream) = nothing
1042-
10431022
read(s::BufferStream, ::Type{UInt8}) = (wait_readnb(s, 1); read(s.buffer, UInt8))
10441023
unsafe_read(s::BufferStream, a::Ptr{UInt8}, nb::UInt) = (wait_readnb(s, Int(nb)); unsafe_read(s.buffer, a, nb))
10451024
nb_available(s::BufferStream) = nb_available(s.buffer)

deps/checksums/libuv-cb6d0f875a5b8ca30cba45c0c1ef7442c87c1e68.tar.gz/md5

-1
This file was deleted.

deps/checksums/libuv-cb6d0f875a5b8ca30cba45c0c1ef7442c87c1e68.tar.gz/sha512

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7248e38acefd92761c54640622357b7b
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2fad17bddc568125d50ce50b7f27aa2de4380400589043d74b180883c96070c2dcad93557f2f5f5416cc297de3a66b35ec8942bd33d8ef1bb22744dad60b760d

deps/libuv.version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
LIBUV_BRANCH=julia-uv1.9.0
2-
LIBUV_SHA1=cb6d0f875a5b8ca30cba45c0c1ef7442c87c1e68
2+
LIBUV_SHA1=ecbd6eddfac4940ab8db57c73166a7378563ebd3

src/init.c

+1-8
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ static struct uv_shutdown_queue_item *next_shutdown_queue_item(struct uv_shutdow
217217

218218
void jl_init_timing(void);
219219
void jl_destroy_timing(void);
220-
void jl_uv_call_close_callback(jl_value_t *val);
221220

222221
JL_DLLEXPORT void jl_atexit_hook(int exitcode)
223222
{
@@ -271,13 +270,6 @@ JL_DLLEXPORT void jl_atexit_hook(int exitcode)
271270
continue;
272271
}
273272
switch(handle->type) {
274-
case UV_PROCESS:
275-
// cause Julia to forget about the Process object
276-
if (handle->data)
277-
jl_uv_call_close_callback((jl_value_t*)handle->data);
278-
// and make libuv think it is already dead
279-
((uv_process_t*)handle)->pid = 0;
280-
// fall-through
281273
case UV_TTY:
282274
case UV_UDP:
283275
case UV_TCP:
@@ -291,6 +283,7 @@ JL_DLLEXPORT void jl_atexit_hook(int exitcode)
291283
case UV_PREPARE:
292284
case UV_CHECK:
293285
case UV_SIGNAL:
286+
case UV_PROCESS:
294287
case UV_FILE:
295288
// These will be shutdown as appropriate by jl_close_uv
296289
jl_close_uv(handle);

src/jl_uv.c

+5-18
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,17 @@ void jl_init_signal_async(void)
7878
}
7979
#endif
8080

81-
void jl_uv_call_close_callback(jl_value_t *val)
81+
static void jl_uv_call_close_callback(jl_value_t *val)
8282
{
8383
jl_value_t *args[2];
8484
args[0] = jl_get_global(jl_base_relative_to(((jl_datatype_t*)jl_typeof(val))->name->module),
8585
jl_symbol("_uv_hook_close")); // topmod(typeof(val))._uv_hook_close
8686
args[1] = val;
8787
assert(args[0]);
88-
jl_apply(args, 2); // TODO: wrap in try-catch?
88+
jl_apply(args, 2);
8989
}
9090

91-
static void jl_uv_closeHandle(uv_handle_t *handle)
91+
JL_DLLEXPORT void jl_uv_closeHandle(uv_handle_t *handle)
9292
{
9393
// if the user killed a stdio handle,
9494
// revert back to direct stdio FILE* writes
@@ -107,7 +107,7 @@ static void jl_uv_closeHandle(uv_handle_t *handle)
107107
free(handle);
108108
}
109109

110-
static void jl_uv_shutdownCallback(uv_shutdown_t *req, int status)
110+
JL_DLLEXPORT void jl_uv_shutdownCallback(uv_shutdown_t *req, int status)
111111
{
112112
/*
113113
* This happens if the remote machine closes the connecition while we're
@@ -180,21 +180,8 @@ JL_DLLEXPORT int jl_init_pipe(uv_pipe_t *pipe, int writable, int readable,
180180
return err;
181181
}
182182

183-
static void jl_proc_exit_cleanup(uv_process_t *process, int64_t exit_status, int term_signal)
184-
{
185-
uv_close((uv_handle_t*)process, (uv_close_cb)&free);
186-
}
187-
188183
JL_DLLEXPORT void jl_close_uv(uv_handle_t *handle)
189184
{
190-
if (handle->type == UV_PROCESS && ((uv_process_t*)handle)->pid != 0) {
191-
// take ownership of this handle,
192-
// so we can waitpid for the resource to exit and avoid leaving zombies
193-
assert(handle->data == NULL); // make sure Julia has forgotten about it already
194-
((uv_process_t*)handle)->exit_cb = jl_proc_exit_cleanup;
195-
return;
196-
}
197-
198185
if (handle->type == UV_FILE) {
199186
uv_fs_t req;
200187
jl_uv_file_t *fd = (jl_uv_file_t*)handle;
@@ -243,7 +230,7 @@ JL_DLLEXPORT void jl_close_uv(uv_handle_t *handle)
243230

244231
JL_DLLEXPORT void jl_forceclose_uv(uv_handle_t *handle)
245232
{
246-
uv_close(handle, &jl_uv_closeHandle);
233+
uv_close(handle,&jl_uv_closeHandle);
247234
}
248235

249236
JL_DLLEXPORT void jl_uv_associate_julia_struct(uv_handle_t *handle,

test/spawn.jl

+3-7
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,9 @@ let bad = "bad\0name"
265265
end
266266

267267
# issue #12829
268-
let out = Pipe(), echo = `$exename --startup-file=no -e 'print(STDOUT, " 1\t", readstring(STDIN))'`, ready = Condition(), t
268+
let out = Pipe(), echo = `$exename --startup-file=no -e 'print(STDOUT, " 1\t", readstring(STDIN))'`, ready = Condition()
269269
@test_throws ArgumentError write(out, "not open error")
270-
t = @async begin # spawn writer task
270+
@async begin # spawn writer task
271271
open(echo, "w", out) do in1
272272
open(echo, "w", out) do in2
273273
notify(ready)
@@ -282,13 +282,10 @@ let out = Pipe(), echo = `$exename --startup-file=no -e 'print(STDOUT, " 1\t", r
282282
@test isreadable(out)
283283
@test iswritable(out)
284284
close(out.in)
285-
@test !isopen(out.in)
286-
is_windows() || @test !isopen(out.out) # it takes longer to propagate EOF through the Windows event system
287285
@test_throws ArgumentError write(out, "now closed error")
288286
@test isreadable(out)
289287
@test !iswritable(out)
290-
is_windows() && Base.process_events(false) # should be enough steps to fully propagate EOF now
291-
@test !isopen(out)
288+
@test isopen(out)
292289
end
293290
wait(ready) # wait for writer task to be ready before using `out`
294291
@test nb_available(out) == 0
@@ -311,7 +308,6 @@ let out = Pipe(), echo = `$exename --startup-file=no -e 'print(STDOUT, " 1\t", r
311308
@test isempty(read(out))
312309
@test eof(out)
313310
@test desc == "Pipe(open => active, 0 bytes waiting)"
314-
wait(t)
315311
end
316312

317313
# issue #8529

0 commit comments

Comments
 (0)