From 7ee315627c7f6e2b60c415982169230f2f75fcda Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Thu, 11 Jan 2024 12:16:41 -0500 Subject: [PATCH 01/15] fix timers --- src/Curl/Multi.jl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Curl/Multi.jl b/src/Curl/Multi.jl index b017f88..6b7ba99 100644 --- a/src/Curl/Multi.jl +++ b/src/Curl/Multi.jl @@ -68,6 +68,9 @@ function remove_handle(multi::Multi, easy::Easy) done!(multi) end end + Base.atexit() do + close(multi.timer) + end end unpreserve_handle(multi) end @@ -134,6 +137,9 @@ function timer_callback( do_multi(multi) end end + Base.atexit() do + close(multi.timer) + end elseif timeout_ms != -1 @async @error("timer_callback: invalid timeout value", timeout_ms, maxlog=1_000) return -1 From f4cfda7de310ea1d1cd1588c33d89d74331a85f3 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Thu, 11 Jan 2024 12:24:26 -0500 Subject: [PATCH 02/15] register one function --- src/Curl/Multi.jl | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Curl/Multi.jl b/src/Curl/Multi.jl index 6b7ba99..a5682aa 100644 --- a/src/Curl/Multi.jl +++ b/src/Curl/Multi.jl @@ -52,6 +52,12 @@ function add_handle(multi::Multi, easy::Easy) end end +const timer_lock = Base.ReentrantLock() +const timers = Timer[] +Base.atexit() do + foreach(close, timers) +end + function remove_handle(multi::Multi, easy::Easy) lock(multi.lock) do @check curl_multi_remove_handle(multi.handle, easy.handle) @@ -68,9 +74,7 @@ function remove_handle(multi::Multi, easy::Easy) done!(multi) end end - Base.atexit() do - close(multi.timer) - end + @lock timer_lock push!(timers, multi.timer) end unpreserve_handle(multi) end @@ -137,9 +141,7 @@ function timer_callback( do_multi(multi) end end - Base.atexit() do - close(multi.timer) - end + @lock timer_lock push!(timers, multi.timer) elseif timeout_ms != -1 @async @error("timer_callback: invalid timeout value", timeout_ms, maxlog=1_000) return -1 From 1bc36b9541371e42ccea564bfc78a1c9e3b4e066 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Thu, 11 Jan 2024 12:27:55 -0500 Subject: [PATCH 03/15] capitalization --- src/Curl/Multi.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Curl/Multi.jl b/src/Curl/Multi.jl index a5682aa..41ce080 100644 --- a/src/Curl/Multi.jl +++ b/src/Curl/Multi.jl @@ -52,10 +52,10 @@ function add_handle(multi::Multi, easy::Easy) end end -const timer_lock = Base.ReentrantLock() -const timers = Timer[] +const TIMERS_LOCK = Base.ReentrantLock() +const TIMERS = Timer[] Base.atexit() do - foreach(close, timers) + foreach(close, TIMERS_LOCK) end function remove_handle(multi::Multi, easy::Easy) @@ -74,7 +74,7 @@ function remove_handle(multi::Multi, easy::Easy) done!(multi) end end - @lock timer_lock push!(timers, multi.timer) + @lock timer_lock push!(TIMERS, multi.timer) end unpreserve_handle(multi) end @@ -141,7 +141,7 @@ function timer_callback( do_multi(multi) end end - @lock timer_lock push!(timers, multi.timer) + @lock timer_lock push!(TIMERS, multi.timer) elseif timeout_ms != -1 @async @error("timer_callback: invalid timeout value", timeout_ms, maxlog=1_000) return -1 From 82b8da5d6ccce202e653b0bdb4a422a85fe43223 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Thu, 11 Jan 2024 12:29:22 -0500 Subject: [PATCH 04/15] capitalization fixup --- src/Curl/Multi.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Curl/Multi.jl b/src/Curl/Multi.jl index 41ce080..6badd7a 100644 --- a/src/Curl/Multi.jl +++ b/src/Curl/Multi.jl @@ -74,7 +74,7 @@ function remove_handle(multi::Multi, easy::Easy) done!(multi) end end - @lock timer_lock push!(TIMERS, multi.timer) + @lock TIMER_LOCK push!(TIMERS, multi.timer) end unpreserve_handle(multi) end @@ -141,7 +141,7 @@ function timer_callback( do_multi(multi) end end - @lock timer_lock push!(TIMERS, multi.timer) + @lock TIMER_LOCK push!(TIMERS, multi.timer) elseif timeout_ms != -1 @async @error("timer_callback: invalid timeout value", timeout_ms, maxlog=1_000) return -1 From a5ae02eddc7e9df8e6448f12df276af8bec9275f Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Fri, 12 Jan 2024 15:11:33 -0500 Subject: [PATCH 05/15] collect Multis as weak refs for atexit cleanup --- src/Curl/Multi.jl | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Curl/Multi.jl b/src/Curl/Multi.jl index 6badd7a..ccf50d3 100644 --- a/src/Curl/Multi.jl +++ b/src/Curl/Multi.jl @@ -8,6 +8,7 @@ mutable struct Multi function Multi(grace::Integer = typemax(UInt64)) multi = new(ReentrantLock(), C_NULL, nothing, Easy[], grace) finalizer(done!, multi) + @lock MULTIS_LOCK push!(MULTIS, WeakRef(multi)) return multi end end @@ -52,10 +53,13 @@ function add_handle(multi::Multi, easy::Easy) end end -const TIMERS_LOCK = Base.ReentrantLock() -const TIMERS = Timer[] +const MULTIS_LOCK = Base.ReentrantLock() +const MULTIS = WeakRef[] +# Close any Multis and their timers at exit that haven't been finalized by then Base.atexit() do - foreach(close, TIMERS_LOCK) + for w in MULTIS + w.value isa Multi && done!(w.value) + end end function remove_handle(multi::Multi, easy::Easy) @@ -74,7 +78,6 @@ function remove_handle(multi::Multi, easy::Easy) done!(multi) end end - @lock TIMER_LOCK push!(TIMERS, multi.timer) end unpreserve_handle(multi) end @@ -141,7 +144,6 @@ function timer_callback( do_multi(multi) end end - @lock TIMER_LOCK push!(TIMERS, multi.timer) elseif timeout_ms != -1 @async @error("timer_callback: invalid timeout value", timeout_ms, maxlog=1_000) return -1 From 4712512314c4adbd3b7fa3013e416eb193f4a4d0 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Fri, 12 Jan 2024 15:11:41 -0500 Subject: [PATCH 06/15] revert previous workaround --- src/Downloads.jl | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Downloads.jl b/src/Downloads.jl index 6a91312..8d3cace 100644 --- a/src/Downloads.jl +++ b/src/Downloads.jl @@ -467,11 +467,8 @@ end # Precompile let - d = Downloader(; grace=0.01) + d = Downloader() download("file://" * @__FILE__; downloader=d) - # Ref https://github.com/JuliaLang/julia/issues/49513 - # we wait for the grace task to finish - sleep(0.05) precompile(Tuple{typeof(Downloads.download), String, String}) precompile(Tuple{typeof(Downloads.Curl.status_2xx_ok), Int64}) end From 79fbe3870ef5ed5de4e75d36908bc6846c8c9b3e Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Fri, 12 Jan 2024 15:16:10 -0500 Subject: [PATCH 07/15] make work on older julia versions --- src/Curl/Multi.jl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Curl/Multi.jl b/src/Curl/Multi.jl index ccf50d3..f372874 100644 --- a/src/Curl/Multi.jl +++ b/src/Curl/Multi.jl @@ -8,7 +8,12 @@ mutable struct Multi function Multi(grace::Integer = typemax(UInt64)) multi = new(ReentrantLock(), C_NULL, nothing, Easy[], grace) finalizer(done!, multi) - @lock MULTIS_LOCK push!(MULTIS, WeakRef(multi)) + lock(MULTIS_LOCK) + try + push!(MULTIS, WeakRef(multi)) + catch + unlock(MULTIS_LOCK) + end return multi end end From 128d1a836713d2984ee0aea777747a27849ab2d1 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Fri, 12 Jan 2024 15:32:56 -0500 Subject: [PATCH 08/15] Revert "make work on older julia versions" This reverts commit 79fbe3870ef5ed5de4e75d36908bc6846c8c9b3e. --- src/Curl/Multi.jl | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Curl/Multi.jl b/src/Curl/Multi.jl index f372874..ccf50d3 100644 --- a/src/Curl/Multi.jl +++ b/src/Curl/Multi.jl @@ -8,12 +8,7 @@ mutable struct Multi function Multi(grace::Integer = typemax(UInt64)) multi = new(ReentrantLock(), C_NULL, nothing, Easy[], grace) finalizer(done!, multi) - lock(MULTIS_LOCK) - try - push!(MULTIS, WeakRef(multi)) - catch - unlock(MULTIS_LOCK) - end + @lock MULTIS_LOCK push!(MULTIS, WeakRef(multi)) return multi end end From fa7940b0abffb50bddf8fa68d8c2a6f96bbe0271 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Fri, 12 Jan 2024 15:34:03 -0500 Subject: [PATCH 09/15] suggestions --- src/Curl/Multi.jl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Curl/Multi.jl b/src/Curl/Multi.jl index ccf50d3..c6ed079 100644 --- a/src/Curl/Multi.jl +++ b/src/Curl/Multi.jl @@ -8,7 +8,7 @@ mutable struct Multi function Multi(grace::Integer = typemax(UInt64)) multi = new(ReentrantLock(), C_NULL, nothing, Easy[], grace) finalizer(done!, multi) - @lock MULTIS_LOCK push!(MULTIS, WeakRef(multi)) + @lock MULTIS_LOCK push!(filter!(m -> m.value isa Multi, MULTIS), WeakRef(multi)) return multi end end @@ -57,8 +57,11 @@ const MULTIS_LOCK = Base.ReentrantLock() const MULTIS = WeakRef[] # Close any Multis and their timers at exit that haven't been finalized by then Base.atexit() do - for w in MULTIS - w.value isa Multi && done!(w.value) + while true + w = @lock MULTIS_LOCK (isempty(MULTIS) ? nothing : pop!(MULTIS)) + w === nothing && break + w = w.value + w isa Multi && done!(w) end end From a27a0da902e2019055085083a296ba0bbe5d9c61 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Fri, 12 Jan 2024 15:36:11 -0500 Subject: [PATCH 10/15] bump julia compat to 1.6 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index d578dd5..d366c67 100644 --- a/Project.toml +++ b/Project.toml @@ -13,7 +13,7 @@ NetworkOptions = "ca575930-c2e3-43a9-ace4-1e988b2c1908" ArgTools = "1.1" LibCURL = "0.6" NetworkOptions = "1.2" -julia = "1.3" +julia = "1.6" [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" From aa0b112138a5a1db54188f580a75ace459928429 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Fri, 12 Jan 2024 15:36:17 -0500 Subject: [PATCH 11/15] update CI --- .github/workflows/ci.yml | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2360a13..709eaf6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,11 +3,11 @@ on: pull_request: branches: - master - - release-1.4 + - release-* push: branches: - master - - release-1.4 + - release-* tags: '*' jobs: test: @@ -17,7 +17,7 @@ jobs: fail-fast: false matrix: version: - - '1.3' + - '1.6' - '1' # automatically expands to the latest stable 1.x release of Julia. - 'nightly' os: @@ -32,21 +32,12 @@ jobs: - os: macOS-latest arch: x86 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: julia-actions/setup-julia@v1 with: version: ${{ matrix.version }} arch: ${{ matrix.arch }} - - uses: actions/cache@v1 - env: - cache-name: cache-artifacts - with: - path: ~/.julia/artifacts - key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }} - restore-keys: | - ${{ runner.os }}-test-${{ env.cache-name }}- - ${{ runner.os }}-test-${{ matrix.os }} - ${{ runner.os }}- + - uses: julia-actions/cache@v1 - run: julia --color=yes .ci/test_and_change_uuid.jl - uses: julia-actions/julia-buildpkg@v1 - uses: julia-actions/julia-runtest@v1 From 06f103cff6eed7ce77ca26f24702d5cc2f6b2dd9 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Fri, 12 Jan 2024 15:41:48 -0500 Subject: [PATCH 12/15] qualify `Base.@lock` --- src/Curl/Multi.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Curl/Multi.jl b/src/Curl/Multi.jl index c6ed079..782b554 100644 --- a/src/Curl/Multi.jl +++ b/src/Curl/Multi.jl @@ -8,7 +8,7 @@ mutable struct Multi function Multi(grace::Integer = typemax(UInt64)) multi = new(ReentrantLock(), C_NULL, nothing, Easy[], grace) finalizer(done!, multi) - @lock MULTIS_LOCK push!(filter!(m -> m.value isa Multi, MULTIS), WeakRef(multi)) + Base.@lock MULTIS_LOCK push!(filter!(m -> m.value isa Multi, MULTIS), WeakRef(multi)) return multi end end @@ -58,7 +58,7 @@ const MULTIS = WeakRef[] # Close any Multis and their timers at exit that haven't been finalized by then Base.atexit() do while true - w = @lock MULTIS_LOCK (isempty(MULTIS) ? nothing : pop!(MULTIS)) + w = Base.@lock MULTIS_LOCK (isempty(MULTIS) ? nothing : pop!(MULTIS)) w === nothing && break w = w.value w isa Multi && done!(w) From ab8a69a2088770d46adc5b11679c542eb1795691 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Fri, 12 Jan 2024 15:43:31 -0500 Subject: [PATCH 13/15] go back to 1.3 but keep 1.6 CI --- .github/workflows/ci.yml | 1 + Project.toml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 709eaf6..b5d735a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,6 +17,7 @@ jobs: fail-fast: false matrix: version: + - '1.3' - '1.6' - '1' # automatically expands to the latest stable 1.x release of Julia. - 'nightly' diff --git a/Project.toml b/Project.toml index d366c67..d578dd5 100644 --- a/Project.toml +++ b/Project.toml @@ -13,7 +13,7 @@ NetworkOptions = "ca575930-c2e3-43a9-ace4-1e988b2c1908" ArgTools = "1.1" LibCURL = "0.6" NetworkOptions = "1.2" -julia = "1.6" +julia = "1.3" [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" From ed67afef5b8771679b3f5c72b58ee7c0cf681dbb Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Fri, 12 Jan 2024 15:47:28 -0500 Subject: [PATCH 14/15] import `@lock` properly --- src/Curl/Curl.jl | 1 + src/Curl/Multi.jl | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Curl/Curl.jl b/src/Curl/Curl.jl index fa76379..3fc9310 100644 --- a/src/Curl/Curl.jl +++ b/src/Curl/Curl.jl @@ -26,6 +26,7 @@ export add_handle, remove_handle +using Base: @lock using LibCURL using LibCURL: curl_off_t, libcurl # not exported: https://github.com/JuliaWeb/LibCURL.jl/issues/87 diff --git a/src/Curl/Multi.jl b/src/Curl/Multi.jl index 782b554..c6ed079 100644 --- a/src/Curl/Multi.jl +++ b/src/Curl/Multi.jl @@ -8,7 +8,7 @@ mutable struct Multi function Multi(grace::Integer = typemax(UInt64)) multi = new(ReentrantLock(), C_NULL, nothing, Easy[], grace) finalizer(done!, multi) - Base.@lock MULTIS_LOCK push!(filter!(m -> m.value isa Multi, MULTIS), WeakRef(multi)) + @lock MULTIS_LOCK push!(filter!(m -> m.value isa Multi, MULTIS), WeakRef(multi)) return multi end end @@ -58,7 +58,7 @@ const MULTIS = WeakRef[] # Close any Multis and their timers at exit that haven't been finalized by then Base.atexit() do while true - w = Base.@lock MULTIS_LOCK (isempty(MULTIS) ? nothing : pop!(MULTIS)) + w = @lock MULTIS_LOCK (isempty(MULTIS) ? nothing : pop!(MULTIS)) w === nothing && break w = w.value w isa Multi && done!(w) From ab79e25d616ab5def21ccc0048d0548dac74483a Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Fri, 12 Jan 2024 16:47:09 -0500 Subject: [PATCH 15/15] skip windows 1.3 CI --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b5d735a..2d93316 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,6 +32,8 @@ jobs: exclude: - os: macOS-latest arch: x86 + - os: windows-latest + version: '1.3' # `curl_easy_setopt: 48` error on github CI steps: - uses: actions/checkout@v4 - uses: julia-actions/setup-julia@v1