swiftlang / swift-corelibs-foundation

The Foundation Project, providing core utilities, internationalization, and OS independence
swift.org
Apache License 2.0
5.28k stars 1.13k forks source link

[SR-6069] SIGPIPE in libcurl #4407

Open swift-ci opened 7 years ago

swift-ci commented 7 years ago
Previous ID SR-6069
Radar None
Original Reporter tedgoddard (JIRA User)
Type Bug
Environment Swift version 4.0.1-dev (LLVM 2dedb62a0b, Clang ab7472e733, Swift 7efb2d13a2) Target: x86_64-unknown-linux-gnu swift-4.0-DEVELOPMENT-SNAPSHOT-2017-10-04-a-ubuntu16.10.tar.gz
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Foundation | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 2e0660fb3c09541baabb995867e3e417

Issue Description:

The following stacktrace is observed:

* thread #​17, name = 'Test', stop reason = signal SIGPIPE
  * frame #​0: 0x00007ffff68f968d libpthread.so.0`__GI___write + 45
    frame #​1: 0x00007ffff52d8935 libcrypto.so.1.0.0`___lldb_unnamed_symbol588$$libcrypto.so.1.0.0 + 37
    frame #​2: 0x00007ffff52d694b libcrypto.so.1.0.0`BIO_write + 107
    frame #​3: 0x00007ffff562fc62 libssl.so.1.0.0`___lldb_unnamed_symbol83$$libssl.so.1.0.0 + 114
    frame #​4: 0x00007ffff5631e83 libssl.so.1.0.0`___lldb_unnamed_symbol89$$libssl.so.1.0.0 + 51
    frame #​5: 0x00007ffff562dac2 libssl.so.1.0.0`___lldb_unnamed_symbol57$$libssl.so.1.0.0 + 162
    frame #​6: 0x00007ffff26548a9 libcurl.so.4`___lldb_unnamed_symbol667$$libcurl.so.4 + 25
    frame #​7: 0x00007ffff26586e9 libcurl.so.4`___lldb_unnamed_symbol680$$libcurl.so.4 + 41
    frame #​8: 0x00007ffff2624330 libcurl.so.4`___lldb_unnamed_symbol179$$libcurl.so.4 + 320
    frame #​9: 0x00007ffff26243f4 libcurl.so.4`___lldb_unnamed_symbol180$$libcurl.so.4 + 116
    frame #​10: 0x00007ffff2624429 libcurl.so.4`___lldb_unnamed_symbol181$$libcurl.so.4 + 9
    frame #​11: 0x00007ffff264ef42 libcurl.so.4`___lldb_unnamed_symbol591$$libcurl.so.4 + 114
    frame #​12: 0x00007ffff2627c80 libcurl.so.4`___lldb_unnamed_symbol196$$libcurl.so.4 + 11616
    frame #​13: 0x00007ffff2639ac3 libcurl.so.4`___lldb_unnamed_symbol340$$libcurl.so.4 + 2291
    frame #​14: 0x00007ffff263adbd libcurl.so.4`___lldb_unnamed_symbol341$$libcurl.so.4 + 397
    frame #​15: 0x00007ffff263afa7 libcurl.so.4`curl_multi_socket_action + 23
    frame #&#8203;16: 0x00007ffff710432a libFoundation.so`function signature specialization <Arg[0] = Dead> of closure #&#8203;2 (Swift.UnsafeMutableRawPointer, Swift.Int, Swift.Optional<Swift.UnsafeMutableRawPointer>) -> Swift.Int32 in Foundation.URLSession._MultiHandle.(setupCallbacks in _0D88FAB2A36EC056571C12A88F9AC924)() -> () + 122
    frame #&#8203;17: 0x00007ffff710292f libFoundation.so`@objc closure #&#8203;2 (Swift.UnsafeMutableRawPointer, Swift.Int, Swift.Optional<Swift.UnsafeMutableRawPointer>) -> Swift.Int32 in Foundation.URLSession._MultiHandle.(setupCallbacks in _0D88FAB2A36EC056571C12A88F9AC924)() -> () + 15
    frame #&#8203;18: 0x00007ffff2637356 libcurl.so.4`___lldb_unnamed_symbol318$$libcurl.so.4 + 134
    frame #&#8203;19: 0x00007ffff2638bf9 libcurl.so.4`curl_multi_add_handle + 297
    frame #&#8203;20: 0x00007ffff7102a0a libFoundation.so`Foundation.URLSession._MultiHandle.add(Foundation._EasyHandle) -> () + 122
    frame #&#8203;21: 0x00007ffff71073ee libFoundation.so`protocol witness for Foundation.URLSessionProtocol.add(handle: Foundation._EasyHandle) -> () in conformance Foundation.URLSession : Foundation.URLSessionProtocol in Foundation + 30
    frame #&#8203;22: 0x00007ffff7127d12 libFoundation.so`function signature specialization <Arg[0] = Owned To Guaranteed> of Foundation._HTTPURLProtocol.(internalState in _03FC87FB038D1F9226FF5E6BD43EDA8A).didset : Foundation._HTTPURLProtocol._InternalState + 2146
    frame #&#8203;23: 0x00007ffff711c8b7 libFoundation.so`Foundation._HTTPURLProtocol.resume() -> () + 1207
    frame #&#8203;24: 0x00007ffff712bfa8 libFoundation.so`function signature specialization <Arg[0] = Owned To Guaranteed and Exploded> of Foundation._HTTPURLProtocol.startNewTransfer(with: Foundation.URLRequest) -> () + 1416
    frame #&#8203;25: 0x00007ffff711c4d2 libFoundation.so`Foundation._HTTPURLProtocol.resume() -> () + 210
    frame #&#8203;26: 0x00007ffff711c3f9 libFoundation.so`Foundation._HTTPURLProtocol.startLoading() -> () + 9
    frame #&#8203;27: 0x00007ffff7113978 libFoundation.so`function signature specialization <Arg[0] = Owned To Guaranteed> of closure #&#8203;1 () -> () in closure #&#8203;1 () -> () in Foundation.URLSessionTask.resume() -> () + 56
    frame #&#8203;28: 0x00007ffff7116901 libFoundation.so`partial apply forwarder for closure #&#8203;1 () -> () in closure #&#8203;1 () -> () in Foundation.URLSessionTask.resume() -> () + 17
    frame #&#8203;29: 0x00007ffff6ffd850 libFoundation.so`reabstraction thunk helper from @callee_owned () -> () to @callee_unowned @convention(block) () -> () + 32
    frame #&#8203;30: 0x00007ffff7f14fb7 libdispatch.so`_dispatch_call_block_and_release + 7
    frame #&#8203;31: 0x00007ffff7f211f4 libdispatch.so`_dispatch_queue_serial_drain + 468
    frame #&#8203;32: 0x00007ffff7f21a65 libdispatch.so`_dispatch_queue_invoke + 597
    frame #&#8203;33: 0x00007ffff7f23df8 libdispatch.so`_dispatch_worker_thread + 728
    frame #&#8203;34: 0x00007ffff68f06da libpthread.so.0`start_thread + 202
    frame #&#8203;35: 0x00007ffff597bd7f libc.so.6`__GI___clone at clone.S:105
swift-ci commented 7 years ago

Comment by Ted Goddard (JIRA)

Possible libcurl configuration to resolve:

https://curl.haxx.se/libcurl/c/CURLOPT_NOSIGNAL.html

phausler commented 7 years ago

you could add this to your code:

_ = signal(SIGPIPE, SIG_IGN)

swift-ci commented 7 years ago

Comment by Ted Goddard (JIRA)

I have tried that (in main.swift), but I'm not sure if it is propagating to the thread that receives the signal.

It's very difficult to reproduce, so I will test further to confirm that change.

swift-ci commented 7 years ago

Comment by Ted Goddard (JIRA)

I have reproduced a SIGPIPE signal with the provided stacktrace in libcurl and signal(SIGPIPE, SIG_IGN) set in main.swift. Is there a way to confirm if the signal mask is applied to all threads in the process?

swift-ci commented 7 years ago

Comment by Ted Goddard (JIRA)

It might be possible to reproduce this with the following in a docker container:

while true; do python -m SimpleHTTPServer 8000; done
while true; do kill -9 `ps -ef | fgrep python | fgrep SimpleHTTPServer | awk '{print $2}'`; sleep 0.1; done

Then run the test client from SR-5936

lldb -o run -- ./fetch http://localhost:8000

With this procedure I have not reproduced a SIGPIPE, but have reproduced:

Fatal error: Transfer completed, but there's no response.: file Foundation/URLSession/http/HTTPURLProtocol.swift, line 549

* thread #&#8203;2, name = 'fetch', stop reason = signal SIGILL: illegal instruction operand
  * frame #&#8203;0: 0x00007ffff7b2a800 libswiftCore.so`function signature specialization <preserving fragile attribute, Arg[1] = Exploded> of Swift._assertionFailure(Swift.StaticString, Swift.String, file: Swift.StaticString, line: Swift.UInt, flags: Swift.UInt32) -> Swift.Never + 144
    frame #&#8203;1: 0x00007ffff734eef9 libFoundation.so`Foundation._HTTPURLProtocol.transferCompleted(withErrorCode: Swift.Optional<Swift.Int>) -> () + 2425
    frame #&#8203;2: 0x00007ffff734f951 libFoundation.so`protocol witness for Foundation._EasyHandleDelegate.transferCompleted(withErrorCode: Swift.Optional<Swift.Int>) -> () in conformance Foundation._HTTPURLProtocol : Foundation._EasyHandleDelegate in Foundation + 17
    frame #&#8203;3: 0x00007ffff7320bba libFoundation.so`Foundation._EasyHandle.completedTransfer(withErrorCode: Swift.Optional<Swift.Int>) -> () + 74
    frame #&#8203;4: 0x00007ffff733308a libFoundation.so`Foundation.URLSession._MultiHandle.(readMessages in _0D88FAB2A36EC056571C12A88F9AC924)() -> () + 1034
    frame #&#8203;5: 0x00007ffff7334d8e libFoundation.so`function signature specialization <Arg[0] = Owned To Guaranteed> of closure #&#8203;1 () -> () in closure #&#8203;1 () -> () in Foundation.URLSession._MultiHandle.(register in _0D88FAB2A36EC056571C12A88F9AC924)(socket: Swift.Int32, for: Swift.UnsafeMutableRawPointer, what: Swift.Int32, socketSourcePtr: Swift.Optional<Swift.UnsafeMutableRawPointer>) -> Swift.Int32 + 78
    frame #&#8203;6: 0x00007ffff733596a libFoundation.so`partial apply forwarder for closure #&#8203;1 () -> () in closure #&#8203;1 () -> () in Foundation.URLSession._MultiHandle.(register in _0D88FAB2A36EC056571C12A88F9AC924)(socket: Swift.Int32, for: Swift.UnsafeMutableRawPointer, what: Swift.Int32, socketSourcePtr: Swift.Optional<Swift.UnsafeMutableRawPointer>) -> Swift.Int32 + 42
    frame #&#8203;7: 0x00007ffff722d850 libFoundation.so`reabstraction thunk helper from @callee_owned () -> () to @callee_unowned @convention(block) () -> () + 32
    frame #&#8203;8: 0x00007ffff7f3e0ee libdispatch.so`_dispatch_block_async_invoke2 + 78
    frame #&#8203;9: 0x00007ffff7f3a8d0 libdispatch.so`_dispatch_continuation_pop + 288
    frame #&#8203;10: 0x00007ffff7f415b7 libdispatch.so`_dispatch_source_invoke + 551
    frame #&#8203;11: 0x00007ffff7f3c125 libdispatch.so`_dispatch_queue_serial_drain + 261
    frame #&#8203;12: 0x00007ffff7f3ca65 libdispatch.so`_dispatch_queue_invoke + 597
    frame #&#8203;13: 0x00007ffff7f3c125 libdispatch.so`_dispatch_queue_serial_drain + 261
    frame #&#8203;14: 0x00007ffff7f3ca65 libdispatch.so`_dispatch_queue_invoke + 597
    frame #&#8203;15: 0x00007ffff7f3edf8 libdispatch.so`_dispatch_worker_thread + 728
    frame #&#8203;16: 0x00007ffff6b216ba libpthread.so.0`start_thread + 202
    frame #&#8203;17: 0x00007ffff5baf3dd libc.so.6`clone + 109