amenzhinsky / iothub

Azure IoT Hub SDK for Golang
MIT License
53 stars 57 forks source link

share http client & close body #27

Closed michaelperel closed 3 years ago

michaelperel commented 3 years ago

Created with @batslyadams @sujitdmello @giventocode

This PR fixes 2 bugs: (1) In edgeSignRequest the response body is never closed, causing resource leaks. (2) In edgeSignRequest each function call uses its own http client. This causes thousands of connections, and eventually crashes our module and the iotedge runtime within a few minutes. It exhausts the pool of sockets on a ubuntu based linux vm.

With this PR: (1) The response body is closed. (2) The http client is initialized once and shared thereafter.

Here is a picture of the new behavior, where only a few connections are made: MicrosoftTeams-image (1)

Before this PR, after about ~5 minutes, there were over 3600 unix connections which eventually exhausted the resources.

@haylesnortal, would you be able to give this a review? We want to merge this so we can reference it in the telegraf module, instead of using a fork. Thanks :)

sujitdmello commented 3 years ago

Adding a picture showing the number of sockets just increasing within a few minutes and causing the Telegraf container to crash.

image

The above PR fixes this problem and the container is much more stable now.

sujitdmello commented 3 years ago

Thanks @amenzhinsky - When will you cut a release so we can easily reference it in our project?

amenzhinsky commented 3 years ago

@sujitdmello sure https://github.com/amenzhinsky/iothub/releases/tag/v0.6.1