Skip to content

[swift5] Reuse URLSessions#10790

Merged
wing328 merged 3 commits intoOpenAPITools:masterfrom
davidhorvath:swift5-reuse-urlsession
Nov 14, 2021
Merged

[swift5] Reuse URLSessions#10790
wing328 merged 3 commits intoOpenAPITools:masterfrom
davidhorvath:swift5-reuse-urlsession

Conversation

@davidhorvath
Copy link
Copy Markdown
Contributor

@davidhorvath davidhorvath commented Nov 5, 2021

resolve #8562

Creating new URLSession for every request isn't optimal and it is not recommended by Apple.
Also, NSPOSIXErrorDomain Code=28 "No space left on device" will get thrown after too many URLSessions get created.

https://developer.apple.com/videos/play/wwdc2018/714/?time=1646
https://developer.apple.com/videos/play/wwdc2017/709/
https://developer.apple.com/forums/thread/84663
https://stackoverflow.com/questions/67318867/error-domain-nsposixerrordomain-code-28-no-space-left-on-device-userinfo-kcf/67507327#67507327

I've hashed the session's configuration, credentials and sessionDelegate with Hasher so we can reuse URLSessions with the same settings.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master (5.3.0), 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request. @4brunu

@davidhorvath davidhorvath changed the title Swift5 reuse urlsession [swift5] reuse URLSessions Nov 5, 2021
@davidhorvath davidhorvath changed the title [swift5] reuse URLSessions [swift5] Reuse URLSessions Nov 5, 2021
@4brunu
Copy link
Copy Markdown
Contributor

4brunu commented Nov 5, 2021

@davidhorvath Hey, first of all, thanks for this contribution.
Everything looks good to me.
Just one question, did you tested this in a project of yours?
Thanks

@davidhorvath davidhorvath force-pushed the swift5-reuse-urlsession branch 4 times, most recently from 8e66f2b to 8ab1480 Compare November 9, 2021 19:45
@davidhorvath
Copy link
Copy Markdown
Contributor Author

@4brunu I've just updated my PR with the asked changes

@4brunu
Copy link
Copy Markdown
Contributor

4brunu commented Nov 11, 2021

@davidhorvath thanks for making the changes, I left some comments

@davidhorvath davidhorvath force-pushed the swift5-reuse-urlsession branch from 52c5d2e to d2e001d Compare November 11, 2021 15:59
@davidhorvath
Copy link
Copy Markdown
Contributor Author

@4brunu Thanks for the review! I've fixed your comments

@4brunu
Copy link
Copy Markdown
Contributor

4brunu commented Nov 11, 2021

@davidhorvath Thanks for your help fixing this issue.
Did you test those changes in your project?
Do they fix the error NSPOSIXErrorDomain Code=28 "No space left on device"?

@4brunu
Copy link
Copy Markdown
Contributor

4brunu commented Nov 12, 2021

@davidhorvath I have tested this on my local project and it seems that everything is working.
Could you please also test this in your project?
Before those changes, were you able to reproduce the error NSPOSIXErrorDomain Code=28 "No space left on device"?
Could you test to see if that error is still happening?

@davidhorvath
Copy link
Copy Markdown
Contributor Author

davidhorvath commented Nov 12, 2021

@davidhorvath I have tested this on my local project and it seems that everything is working.
Could you please also test this in your project?
Before those changes, were you able to reproduce the error NSPOSIXErrorDomain Code=28 "No space left on device"?
Could you test to see if that error is still happening?

@4brunu I haven't tested the latest version in our project yet but I will later today.
I will get back to you

@davidhorvath
Copy link
Copy Markdown
Contributor Author

davidhorvath commented Nov 13, 2021

@4brunu
I've tested it in our project. Everything is working and I don't get the error message! 🚀

@4brunu
Copy link
Copy Markdown
Contributor

4brunu commented Nov 13, 2021

Nice, thanks for your help 😊

@davidhorvath
Copy link
Copy Markdown
Contributor Author

Nice, thanks for your help 😊

@4brunu Thanks for your support

@wing328 wing328 merged commit 552a31d into OpenAPITools:master Nov 14, 2021
@wing328 wing328 added this to the 5.3.1 milestone Dec 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[REQ] [swift5] Reuse URLSessions for requests

3 participants