Giter Site home page Giter Site logo

Comments (12)

aviau avatar aviau commented on August 21, 2024

Thank you for the detailed bug report! I wonder what we can do about this. Do you have any ideas? Our use of requests seems pretty standard. We might have to send this to the requests team. Or should we create a request session object for every request?

from influxdb-python.

pddenhar avatar pddenhar commented on August 21, 2024

I was able to reproduce the issue using the requests library alone, so I've reported the bug to them.

As for using the library for the time being, it's hard to say. The behavior seems to get more likely to happen proportional to the latency of the internet connection requests are being made on (more latency == more time for the FIN from the server to be in flight but not received). Unfortunately for me, my use of InfluxDB-python is all on devices with extremely high latency internet connections, sometimes up to seconds. This seems to leave a pretty large window where an HTTP request can be sent out while a FIN is in flight from the server, leading to this BadStatusLine error.

For now, it might be best to not use a Session and simply make requests directly using requests.post or requests.get? I honestly can't say for sure that they don't use connection pooling (I'm not experienced with the library) but if so I think it would solve this problem for now.

A side benefit I've been thinking about is that it also might serve to reduce strain on the Influx server, because every single client would not be keeping TCP connections open at all times, but rather opening and closing them upon calls to write_points.

from influxdb-python.

aviau avatar aviau commented on August 21, 2024

The session object does not keep a connection open.

From the requests docs (here):

The Session object allows you to persist certain parameters across requests. It also persists cookies across all requests made from the Session instance.

... or does it?

keep-alive is 100% automatic within a session! Any requests that you make within a session will automatically reuse the appropriate connection!

Would you like to try it out? See this branch.

from influxdb-python.

languitar avatar languitar commented on August 21, 2024

I am also experiencing this issue. Is there any easy workaround?

from influxdb-python.

aviau avatar aviau commented on August 21, 2024

@languitar

Can you try this branch and give us an update please?

from influxdb-python.

languitar avatar languitar commented on August 21, 2024

@ReAzem I can try, but I have no clue how to reliably reproduce the case that I observe. So it might work out or not...

from influxdb-python.

kmacrow avatar kmacrow commented on August 21, 2024

I'm also having this problem. @languitar tried that branch, no improvement.

from influxdb-python.

aviau avatar aviau commented on August 21, 2024

@kmacrow I have pushed a new commit. Can you try again?

This is unrelated to the influxdb-python as this is a requests issue. A fix would be to use an interval longer than 5 seconds.

from influxdb-python.

nekto0n avatar nekto0n commented on August 21, 2024

We had somehow similar issues with requests, keep-alive and broken connections. We had http client, REST server and IPVS balancer in between:

client <-> balancer <-> server

After connection being quiet for a while balancer simply forgets about established TCP connection and subsequent request after a long pause results in RST being received on client side. It is the same as in-flight-FIN race being discussed here.
requests does it's best to check if TCP connection is still alive - it calls poll() with 0 timeout to check connection status upon taking connection from pool, but if client hasn't yet received FIN/RST from server it rightfully assumes that connection can be used and issues HTTP request.

This problem could be worked around by enabling SO_KEEPALIVE on socket, but:

  • Race condition would still be possible
  • There's no interface to set in requests

Our solution was to setup HTTPAdapter in requests so that connection pool size is less than retries count. This works like this, suppose we have connection pool size = 2 and retries count = 3. We take first connection from pool and request fails with socket error, we take second connection from pool and it fails too, so we create new connection and it works (or doesn't, but that's another case).

I took a look at your implementation and as you don't use retries, so these errors are expected and should be handled explicitly.

from influxdb-python.

jove1 avatar jove1 commented on August 21, 2024

I wonder if #124 would have any effect?

from influxdb-python.

aviau avatar aviau commented on August 21, 2024

these errors are expected and should be handled explicitly.

I was hoping for another solution, but you are right. I'll push a patch that tries to send the packet for up to three times.

edit: I have begun working on a fix here 4f17ba3 . I'll write tests before I merge in master.

from influxdb-python.

nekto0n avatar nekto0n commented on August 21, 2024

@jove1 This will put connection back to the pool, but won't close it - so I doubt it will help in this case. (If I'm correct about how requests work)

from influxdb-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.