Comments (12)
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.
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.
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.
I am also experiencing this issue. Is there any easy workaround?
from influxdb-python.
Can you try this branch and give us an update please?
from influxdb-python.
@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.
I'm also having this problem. @languitar tried that branch, no improvement.
from influxdb-python.
@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.
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.
I wonder if #124 would have any effect?
from influxdb-python.
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.
@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)
- No more values inserted into InfluxDB since Sep 1, 2021 0:00 UTC HOT 2
- Cannot use the library with a non-ascii password
- Error creating buckets HOT 1
- Using InfluxDBClient object in context manager HOT 1
- how to set connection pool size
- How to enable gzip and udp
- Tags in write_points: tag_columns not optional when using json protocol HOT 1
- A query with a certain date yields an UnicodeDecodeError when decoding msgpack response
- how to query the result into a dataframe within influxdb2 flux query
- bug: bind_params cause InfluxDBClientError: expected field argument HOT 1
- [feature-request] Adding support for UNIX sockets
- JSONDecodeError in client.query() HOT 2
- Error in documentation about timeout argument?
- 5.3.1 version is untagged on git/github HOT 4
- Identify repo owner and move to InfluxCommunity org HOT 1
- FutureWarning on frame.append method
- Query with time > xxx behaves in the same way as time >= xxx
- v
- Suggestion: run queries copy/pasted from grafana/influx dash HOT 1
- Skipping analyzing "influxdb_client": module is installed, but missing library stubs or py.typed marker
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from influxdb-python.