Skip to content

Commit d8e2380

Browse files
authored
Merge pull request #19307 from JuliaLang/jn/pipe-ulimit
ulimit the max open pipes during testing
2 parents ace5c8b + 1353727 commit d8e2380

File tree

5 files changed

+39
-12
lines changed

5 files changed

+39
-12
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ script:
125125
- /tmp/julia/bin/julia --precompiled=no -e 'true' &&
126126
/tmp/julia/bin/julia-debug --precompiled=no -e 'true'
127127
- /tmp/julia/bin/julia -e 'versioninfo()'
128-
- export JULIA_CPU_CORES=2 && export JULIA_TEST_MAXRSS_MB=600 && cd /tmp/julia/share/julia/test &&
128+
- export JULIA_CPU_CORES=2 && export JULIA_TEST_MAXRSS_MB=600 &&
129+
ulimit -n 128 &&
130+
cd /tmp/julia/share/julia/test &&
129131
/tmp/julia/bin/julia --check-bounds=yes runtests.jl $TESTSTORUN &&
130132
/tmp/julia/bin/julia --check-bounds=yes runtests.jl libgit2-online pkg
131133
- cd `dirname $TRAVIS_BUILD_DIR` && mv julia2 julia &&

base/stream.jl

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,12 @@ function TTY(fd::RawFD; readable::Bool = false)
187187
return tty
188188
end
189189

190-
show(io::IO,stream::LibuvServer) = print(io, typeof(stream), "(", uv_status_string(stream), ")")
191-
show(io::IO, stream::LibuvStream) = print(io, typeof(stream), "(", uv_status_string(stream), ", ",
190+
show(io::IO, stream::LibuvServer) = print(io, typeof(stream), "(",
191+
_fd(stream), " ",
192+
uv_status_string(stream), ")")
193+
show(io::IO, stream::LibuvStream) = print(io, typeof(stream), "(",
194+
_fd(stream), " ",
195+
uv_status_string(stream), ", ",
192196
nb_available(stream.buffer)," bytes waiting)")
193197

194198
# Shared LibuvStream object interface
@@ -521,7 +525,9 @@ end
521525

522526
show(io::IO, stream::Pipe) = print(io,
523527
"Pipe(",
528+
_fd(stream.in), " ",
524529
uv_status_string(stream.in), " => ",
530+
_fd(stream.out), " ",
525531
uv_status_string(stream.out), ", ",
526532
nb_available(stream), " bytes waiting)")
527533

@@ -925,12 +931,16 @@ Connect to the named pipe / UNIX domain socket at `path`.
925931
"""
926932
connect(path::AbstractString) = connect(init_pipe!(PipeEndpoint(); readable=false, writable=false, julia_only=true),path)
927933

934+
const OS_HANDLE = is_windows() ? WindowsRawSocket : RawFD
935+
const INVALID_OS_HANDLE = is_windows() ? WindowsRawSocket(Ptr{Void}(-1)) : RawFD(-1)
928936
_fd(x::IOStream) = RawFD(fd(x))
929-
if is_windows()
930-
_fd(x::LibuvStream) = WindowsRawSocket(
931-
ccall(:jl_uv_handle, Ptr{Void}, (Ptr{Void},), x.handle))
932-
else
933-
_fd(x::LibuvStream) = RawFD(ccall(:jl_uv_handle, Int32, (Ptr{Void},), x.handle))
937+
function _fd(x::Union{LibuvStream, LibuvServer})
938+
fd = Ref{OS_HANDLE}(INVALID_OS_HANDLE)
939+
if x.status != StatusUninit && x.status != StatusClosed
940+
err = ccall(:uv_fileno, Int32, (Ptr{Void}, Ptr{OS_HANDLE}), x.handle, fd)
941+
# handle errors by returning INVALID_OS_HANDLE
942+
end
943+
return fd[]
934944
end
935945

936946
for (x, writable, unix_fd, c_symbol) in

src/dump.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,9 @@ static void jl_serialize_value_(jl_serializer_state *s, jl_value_t *v)
10421042
}
10431043
size_t nf = jl_datatype_nfields(t);
10441044
if (nf == 0 && jl_datatype_size(t)>0) {
1045-
if (t->name == jl_pointer_type->name) {
1045+
if (t->name == jl_pointer_type->name && jl_unbox_voidpointer(v) != (void*)-1) {
1046+
// normalize most pointers to NULL, to help catch memory errors
1047+
// but permit MAP_FAILED / INVALID_HANDLE to be stored unchanged
10461048
write_int32(s->s, 0);
10471049
#ifdef _P64
10481050
write_int32(s->s, 0);

test/Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,17 @@ TESTS = all linalg sparse unicode strings dates $(filter-out TestHelpers runtest
88

99
default: all
1010

11+
# set hard and soft limits for spawn fd-exhaustion test
12+
ifeq ($(OS),WINNT)
13+
ULIMIT_TEST=
14+
else
15+
ULIMIT_TEST=ulimit -n 128
16+
endif
17+
1118
$(TESTS):
12-
@cd $(SRCDIR) && $(call PRINT_JULIA, $(call spawn,$(JULIA_EXECUTABLE)) --check-bounds=yes --startup-file=no ./runtests.jl $@)
19+
@cd $(SRCDIR) && \
20+
$(ULIMIT_TEST) && \
21+
$(call PRINT_JULIA, $(call spawn,$(JULIA_EXECUTABLE)) --check-bounds=yes --startup-file=no ./runtests.jl $@)
1322

1423
perf:
1524
@$(MAKE) -C $(SRCDIR)/perf all

test/spawn.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ let bad = "bad\0name"
283283
end
284284

285285
# issue #12829
286-
let out = Pipe(), echo = `$exename --startup-file=no -e 'print(STDOUT, " 1\t", readstring(STDIN))'`, ready = Condition(), t
286+
let out = Pipe(), echo = `$exename --startup-file=no -e 'print(STDOUT, " 1\t", readstring(STDIN))'`, ready = Condition(), t, infd, outfd
287287
@test_throws ArgumentError write(out, "not open error")
288288
t = @async begin # spawn writer task
289289
open(echo, "w", out) do in1
@@ -295,6 +295,8 @@ let out = Pipe(), echo = `$exename --startup-file=no -e 'print(STDOUT, " 1\t", r
295295
write(in2, "orld\n")
296296
end
297297
end
298+
infd = Base._fd(out.in)
299+
outfd = Base._fd(out.out)
298300
show(out, out)
299301
notify(ready)
300302
@test isreadable(out)
@@ -327,13 +329,15 @@ let out = Pipe(), echo = `$exename --startup-file=no -e 'print(STDOUT, " 1\t", r
327329
@test !isreadable(out)
328330
@test !iswritable(out)
329331
@test !isopen(out)
332+
@test infd != Base._fd(out.in) == Base.INVALID_OS_HANDLE
333+
@test outfd != Base._fd(out.out) == Base.INVALID_OS_HANDLE
330334
@test nb_available(out) == 0
331335
@test c == UInt8['w']
332336
@test lstrip(ln2) == "1\thello\n"
333337
@test ln1 == "orld\n"
334338
@test isempty(read(out))
335339
@test eof(out)
336-
@test desc == "Pipe(open => active, 0 bytes waiting)"
340+
@test desc == "Pipe($infd open => $outfd active, 0 bytes waiting)"
337341
wait(t)
338342
end
339343

0 commit comments

Comments
 (0)