swift-foundation icon indicating copy to clipboard operation
swift-foundation copied to clipboard

[SR-15255] Windows: Calling URL(contentsOf:) repeatedly crashes

Open adam-fowler opened this issue 4 years ago • 3 comments
trafficstars

Previous ID SR-15255
Radar None
Original Reporter @adam-fowler
Type Bug

Environment

Run inside GitHub action using `compnerd/gha-setup-swift`

jobs:
  windows:
    runs-on: windows-latest
    steps:
      - uses: compnerd/gha-setup-swift@main
        with:
          branch: swift-5.5-release
          tag: 5.5-RELEASE
      - uses: actions/checkout@v2
      - run: swift test

I don't have a Windows setup so cannot test locally

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee None
Priority Medium

md5: fad9bd9ca6233534ee2375c19875deab

Issue Description:

The following code crashes on Windows.

func testURLs() throws {
    for _ in 0..<20 {
        if let url = URL(string: "https://raw.githubusercontent.com/jmespath/jmespath.test/master/tests/filters.json") {
            _ = try Data(contentsOf: url)
        }
    }
}

adam-fowler avatar Sep 28 '21 14:09 adam-fowler

From a quick test today, seems that the failure occurs in the URL creation.

The following fails:

import Foundation
let url = URL(string: "https://raw.githubusercontent.com/jmespath/jmespath.test/master/tests/filters.json")

compnerd avatar May 07 '22 01:05 compnerd

I found it crashed while inside Data(contentsOf) on another thread with this call stack

dispatch_debug (@dispatch_debug:994)
voucher_copy (@voucher_copy:588)
dispatch_source_set_registration_handler_f (@dispatch_source_set_registration_handler_f:489)
dispatch_queue_set_width (@dispatch_queue_set_width:527)
dispatch_workloop_set_cpupercent (@dispatch_workloop_set_cpupercent:2475)
dispatch_workloop_set_cpupercent (@dispatch_workloop_set_cpupercent:2414)
_dispatch_prohibit_transition_to_multithreaded (@_dispatch_prohibit_transition_to_multithreaded:2572)
_recalloc (@_recalloc:30)
BaseThreadInitThunk (@BaseThreadInitThunk:8)
RtlUserThreadStart (@RtlUserThreadStart:13)

The main thread callstack is

NtWaitForAlertByThreadId (@NtWaitForAlertByThreadId:8)
RtlSleepConditionVariableSRW (@RtlSleepConditionVariableSRW:87)
SleepConditionVariableSRW (@SleepConditionVariableSRW:14)
FoundationNetworking._NSNonfileURLContentLoader.contentsOf(url: Foundation.URL) throws -> (result: Foundation.NSData, textEncodingNameIfAvailable: Swift.Optional<Swift.String>) (@FoundationNetworking._NSNonfileURLContentLoader.contentsOf(url: Foundation.URL) throws -> (result: Foundation.NSData, textEncodingNameIfAvailable: Swift.Optional<Swift.String>):118)
type metadata accessor for FoundationNetworking._NSNonfileURLContentLoader (@type metadata accessor for FoundationNetworking._NSNonfileURLContentLoader:341)
Foundation.NSData.__allocating_init(base64Encoded: Swift.String, options: Foundation.NSData.Base64DecodingOptions) -> Swift.Optional<Foundation.NSData> (@Foundation.NSData.__allocating_init(base64Encoded: Swift.String, options: Foundation.NSData.Base64DecodingOptions) -> Swift.Optional<Foundation.NSData>:432)
Foundation.NSData.init(contentsOf: Foundation.URL, options: Foundation.NSData.ReadingOptions) throws -> Foundation.NSData (@Foundation.NSData.init(contentsOf: Foundation.URL, options: Foundation.NSData.ReadingOptions) throws -> Foundation.NSData:45)
Foundation.NSData.__allocating_init(contentsOf: Foundation.URL, options: Foundation.NSData.ReadingOptions) throws -> Foundation.NSData (@Foundation.NSData.__allocating_init(contentsOf: Foundation.URL, options: Foundation.NSData.ReadingOptions) throws -> Foundation.NSData:20)
Foundation.Data.init(contentsOf: __shared Foundation.URL, options: Foundation.NSData.ReadingOptions) throws -> Foundation.Data (@Foundation.Data.init(contentsOf: __shared Foundation.URL, options: Foundation.NSData.ReadingOptions) throws -> Foundation.Data:22)
JMESPathTests.ComplianceTests.testURLs() throws -> () (c:\Users\User\Developer\server\jmespath.swift\Tests\JMESPathTests\ComplianceTests.swift:218)
implicit closure apple/swift#30 () throws -> () in implicit closure apple/swift#29 (JMESPathTests.ComplianceTests) -> () throws -> () in variable initialization expression of static JMESPathTests.ComplianceTests.__allTests__ComplianceTests : Swift.Array<(Swift.String, (JMESPathTests.ComplianceTests) -> () throws -> ())> (c:\Users\User\Developer\server\jmespath.swift\.build\x86_64-unknown-windows-msvc\debug\jmespath.swiftPackageTests.derived\JMESPathTests.swift:21)
partial apply forwarder for implicit closure apple/swift#30 () throws -> () in implicit closure apple/swift#29 (JMESPathTests.ComplianceTests) -> () throws -> () in variable initialization expression of static JMESPathTests.ComplianceTests.__allTests__ComplianceTests : Swift.Array<(Swift.String, (JMESPathTests.ComplianceTests) -> () throws -> ())> (@jmespath_swiftPackageTests.__JMESPathTests__allTests() -> Swift.Array<(testCaseClass: XCTest.XCTestCase.Type, allTests: Swift.Array<(Swift.String, (XCTest.XCTestCase) throws -> ())>)>:1598)
reabstraction thunk helper from @escaping @callee_guaranteed () -> (@error @owned Swift.Error) to @escaping @callee_guaranteed () -> (@out (), @error @owned Swift.Error) (@jmespath_swiftPackageTests.__JMESPathTests__allTests() -> Swift.Array<(testCaseClass: XCTest.XCTestCase.Type, allTests: Swift.Array<(Swift.String, (XCTest.XCTestCase) throws -> ())>)>:1802)
reabstraction thunk helper from @escaping @callee_guaranteed () -> (@error @owned Swift.Error) to @escaping @callee_guaranteed () -> (@out (), @error @owned Swift.Error)partial apply forwarder with unmangled suffix ".311" (@jmespath_swiftPackageTests.__JMESPathTests__allTests() -> Swift.Array<(testCaseClass: XCTest.XCTestCase.Type, allTests: Swift.Array<(Swift.String, (XCTest.XCTestCase) throws -> ())>)>:1740)
type metadata accessor for XCTest.XCTestCase (@type metadata accessor for XCTest.XCTestCase:264)
type metadata accessor for XCTest.XCTestCase (@type metadata accessor for XCTest.XCTestCase:159)
type metadata accessor for XCTest.XCTestCase (@type metadata accessor for XCTest.XCTestCase:112)
XCTest.XCTestCase.init() -> XCTest.XCTestCase (@XCTest.XCTestCase.init() -> XCTest.XCTestCase:24)
180004ACC (@7ffc58774acc..7ffc58774b3c:3)
XCTest.XCTestCase.invokeTest() -> () (@XCTest.XCTestCase.invokeTest() -> ():134)

adam-fowler avatar May 09 '22 16:05 adam-fowler

@parkera Please transfer this.

AnthonyLatsis avatar Nov 06 '23 09:11 AnthonyLatsis