Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DNS query failure in async paradigm #4

Closed
novi opened this issue Sep 17, 2019 · 7 comments
Closed

DNS query failure in async paradigm #4

novi opened this issue Sep 17, 2019 · 7 comments

Comments

@novi
Copy link

novi commented Sep 17, 2019

DNS request will failure with this async test as expected.

2019-09-17 15:14:22.499290+0900 xctest[7603:427732] [si_destination_compare] send failed: Invalid argument
2019-09-17 15:14:22.499516+0900 xctest[7603:427732] [si_destination_compare] send failed: Undefined error: 0
NioDNS/Tests/DNSClientTests/DNSClientTests.swift:54: error: -[DNSClientTests.DNSClientTests testSRVRecordsAsync] : Asynchronous wait failed: Exceeded timeout of 5 seconds, with unfulfilled expectations: "getSRVRecords".

No callback is called and it shows send failed error in console.

@Joannis
Copy link
Member

Joannis commented Mar 24, 2020

I'm sorry that I missed this issue. Is this still an issue with the recent versions, since I am relying on this code.

@Joannis
Copy link
Member

Joannis commented Nov 14, 2021

Closing this, as send failed is a known bug in SwiftNIO and doesn't affect NIODNS

@Joannis Joannis closed this as completed Nov 14, 2021
@alessionossa
Copy link
Contributor

alessionossa commented Dec 22, 2021

I think the send failed error is unrelated to the issue reported by @novi , and that you can reproduce with his test.
The send failed issue is just a "false error", but the request is correctly sent to the server.
The error here, instead, is that for some reason the library doesn’t complete/return the Future when using asynchronous code instead of .wait().

I have faced the same issue and found this thread after I checked with Wireshark that the request was correctly sent to the server and the server responded correctly.

Please, reopen the issue.

It looks like the last code that gets executed is the following:
https://github.com/orlandos-nl/NioDNS/blob/de0b66fdedab85b4b84535df3efbef2e6605f89b/Sources/DNSClient/DNSClient%2BQuery.swift#L96-L109

The problem, in particular, is present only when the client connection is async like here:

DNSClient.connect(on: group, host: "8.8.8.8").flatMap({ client in
    client.getSRVRecords(from: "_mongodb._tcp.ok0-xkvc1.mongodb.net")
})

in fact, the following test succeed:

func testSRVRecordsSyncClient() throws {
    let expectation = self.expectation(description: "getSRVRecords")

    dnsClient.getSRVRecords(from: "_mongodb._tcp.ok0-xkvc1.mongodb.net")
    .whenComplete { (result) in
        switch result {
        case .failure(let error):
            XCTFail("\(error)")
        case .success(let answers):
            print(answers)
            XCTAssertGreaterThanOrEqual(answers.count, 1, "The returned answers should be greater than or equal to 1")
        }
        expectation.fulfill()
    }
    self.waitForExpectations(timeout: 5, handler: nil)
}

Probably, it all goes down to
https://github.com/apple/swift-nio/blob/19403414baa3f1c19a880154c81cbdeda9668acd/Sources/NIOCore/SocketAddresses.swift#L385-L394
which is suggested to be run outside an EventLoop

@Joannis
Copy link
Member

Joannis commented Dec 22, 2021

@alessionossa might it be that Swift deallocated/deinit-ed the DNS client while waiting for a response?

@Joannis Joannis reopened this Dec 22, 2021
@alessionossa
Copy link
Contributor

I just read again Notes and this is probably the case. Thank you for the fast response!

I will open another issue related to ProtocolError as soon as I will reproduce the issue without sensitive data.

@alessionossa
Copy link
Contributor

I think this issue can now be closed

@Joannis
Copy link
Member

Joannis commented Jan 5, 2022

Thanks! Will do.

@Joannis Joannis closed this as completed Jan 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants