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

Connections not closed with NIO #1501

Open
2 tasks done
mbarnach opened this issue Mar 20, 2020 · 13 comments
Open
2 tasks done

Connections not closed with NIO #1501

mbarnach opened this issue Mar 20, 2020 · 13 comments

Comments

@mbarnach
Copy link
Member

Context and Description

When using compiling Kitura with Swift NIO, the connections are not released.
This can be easily demonstrated with a simple application limiting the number of simultaneous connections to 2.

let serverOptions = ServerOptions(connectionLimit: 2)
Kitura.addHTTPServer(onPort: 8080, with: router, options: serverOptions)

Then calling the server more than 2 times will always return a 503.
It seems that this behaviour is affect both Linux and MacOS.

Environment Details

Tried on MacOS 10.15.3 with Swift 5.1.3 and Kitura 2.9.1
Same on Linux with Swift 5.1.5 and Kitura 2.9.1 (Docker swift:5.1.4)

This issue doesn't affect Kitura without NIO!

Could it be a reason for the issue #1499?

Steps to Reproduce

  1. Limit the number of connections to something trackable (eg. 2)
  2. Query any endpoints more than the previous limit
  3. Observe the 503 response.

Expected vs. Actual Behaviour

  • Expected to happen:
    - Connections available again after some time
  • Actually happened:
    - Connections never get available
@Davidde94
Copy link

@mbarnach could you tell me which version of NIO was resolved?

@mbarnach
Copy link
Member Author

mbarnach commented Sep 4, 2020

@Davidde94 I'm still having the issue with the 2.20.2 (latest). I've tried some previous version also, with no luck.

@Davidde94
Copy link

@mbarnach thanks for that. I'm having difficulty reproducing with nc. I've created this extremely simple server:

import Kitura

let router = Router()

let serverOptions = ServerOptions(connectionLimit: 2)
Kitura.addHTTPServer(onPort: 8080, with: router, options: serverOptions)
Kitura.run()

I've then created 3 terminals and run nc localhost 8080 in each of them to create 3 connections. On the third terminal the connection fails as expected. If I then terminate one of the other nc processes, I'm able to create a new connection without issue.

Could you walk me through an exact reproduction?

@mbarnach
Copy link
Member Author

mbarnach commented Sep 4, 2020

Are you compiling with NIO on for Kitura? Like KITURA_NIO swift run

@Davidde94
Copy link

Yep!

david@Davids-Work-MacBook-Pro KituraConnectionTest % env KITURA_NIO=1 swift run
Fetching https://github.com/apple/swift-nio-extras.git
Fetching https://github.com/IBM-Swift/Kitura-NIO.git
Fetching https://github.com/IBM-Swift/TypeDecoder.git
Fetching https://github.com/IBM-Swift/KituraContracts.git
Fetching https://github.com/IBM-Swift/Kitura-TemplateEngine.git
Fetching https://github.com/IBM-Swift/BlueSocket.git
Fetching https://github.com/IBM-Swift/LoggerAPI.git
Fetching https://github.com/apple/swift-nio.git
Fetching https://github.com/apple/swift-nio-ssl.git
Fetching https://github.com/IBM-Swift/BlueSSLService.git
Fetching https://github.com/IBM-Swift/Kitura
Fetching https://github.com/apple/swift-log.git
...

@Davidde94
Copy link

How're you making the connections?

@mbarnach
Copy link
Member Author

mbarnach commented Sep 4, 2020

I'm usually using POSTMAN. Let me try to reproduce your setup to see if I get the same behaviour.

@Davidde94
Copy link

I'm able to reproduce with postman, I suspect it's something todo with Keep-Alive. Postman is trying to make a new connection on every request, but not terminating connections from previous requests. I'll try and confirm this.

@Davidde94
Copy link

This seems suspiciously similar: https://community.postman.com/t/terminate-connection/2351

@Davidde94
Copy link

Running multiple requests via curl also succeeds. libcurl reuses connections by default.

@mbarnach
Copy link
Member Author

mbarnach commented Sep 4, 2020

When settings Connection: close on Postman, as suggested by the Postman thread, it still doesn't work.
The fact that curl is re-using the connection means they are not close, right? So it confirms the issue?

@Davidde94
Copy link

Alright I think I have a reproduction. Let me have a look and get back to you.

@Davidde94
Copy link

Sorry for the delay, it's a busy time here at Apple. I had a look again today and found the source of the issue. It's a minor fix in Kitura-NIO. Details are here: Kitura/Kitura-NIO#241

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

2 participants