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

BMW Connected Drive permanentally closes connection #72054

Closed
arboeh opened this issue May 18, 2022 · 19 comments · Fixed by #72653
Closed

BMW Connected Drive permanentally closes connection #72054

arboeh opened this issue May 18, 2022 · 19 comments · Fixed by #72653

Comments

@arboeh
Copy link

arboeh commented May 18, 2022

The problem

BMW Connected Drive "drives" me crazy. It permanetally closes connection and gives the following error:

2022-05-18 07_17_10-Window

What version of Home Assistant Core has the issue?

core-2022.5.4

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

BMW Connected Drive

Link to integration documentation on our website

https://www.home-assistant.io/integrations/bmw_connected_drive

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Protokolldetails (FEHLER)
Dieser Fehler wurde von einer benutzerdefinierten Integration verursacht
Logger: custom_components.bmw_connected_drive.coordinator
Source: custom_components/bmw_connected_drive/coordinator.py:54
Integration: BMW Connected Drive
First occurred: 07:04:03 (1 occurrences)
Last logged: 07:04:03

Unexpected error fetching bmw_connected_drive-xxx.yyy@zzz.de data: The connection pool was closed while 1 HTTP requests/responses were still in-flight.
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/anyio/streams/tls.py", line 108, in _call_sslobject_method
    result = func(*args)
  File "/usr/local/lib/python3.9/ssl.py", line 888, in read
    v = self._sslobj.read(len)
ssl.SSLWantReadError: The operation did not complete (read) (_ssl.c:2633)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/httpcore/backends/asyncio.py", line 31, in read
    return await self._stream.receive(max_bytes=max_bytes)
  File "/usr/local/lib/python3.9/site-packages/anyio/streams/tls.py", line 171, in receive
    data = await self._call_sslobject_method(self._ssl_object.read, max_bytes)
  File "/usr/local/lib/python3.9/site-packages/anyio/streams/tls.py", line 115, in _call_sslobject_method
    data = await self.transport_stream.receive()
  File "/usr/local/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 1105, in receive
    await self._protocol.read_event.wait()
  File "/usr/local/lib/python3.9/asyncio/locks.py", line 226, in wait
    await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/httpcore/_exceptions.py", line 8, in map_exceptions
    yield
  File "/usr/local/lib/python3.9/site-packages/httpcore/backends/asyncio.py", line 33, in read
    return b""
  File "/usr/local/lib/python3.9/site-packages/anyio/_core/_tasks.py", line 103, in __exit__
    raise TimeoutError
TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 60, in map_httpcore_exceptions
    yield
  File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 353, in handle_async_request
    resp = await self._pool.handle_async_request(req)
  File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection_pool.py", line 253, in handle_async_request
    raise exc
  File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection_pool.py", line 237, in handle_async_request
    response = await connection.handle_async_request(request)
  File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection.py", line 90, in handle_async_request
    return await self._connection.handle_async_request(request)
  File "/usr/local/lib/python3.9/site-packages/httpcore/_async/http11.py", line 102, in handle_async_request
    raise exc
  File "/usr/local/lib/python3.9/site-packages/httpcore/_async/http11.py", line 81, in handle_async_request
    ) = await self._receive_response_headers(**kwargs)
  File "/usr/local/lib/python3.9/site-packages/httpcore/_async/http11.py", line 143, in _receive_response_headers
    event = await self._receive_event(timeout=timeout)
  File "/usr/local/lib/python3.9/site-packages/httpcore/_async/http11.py", line 172, in _receive_event
    data = await self._network_stream.read(
  File "/usr/local/lib/python3.9/site-packages/httpcore/backends/asyncio.py", line 33, in read
    return b""
  File "/usr/local/lib/python3.9/contextlib.py", line 137, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/usr/local/lib/python3.9/site-packages/httpcore/_exceptions.py", line 12, in map_exceptions
    raise to_exc(exc)
httpcore.ReadTimeout

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/bimmer_connected/account.py", line 78, in get_vehicles
    vehicles_responses: List[httpx.Response] = await asyncio.gather(*vehicles_tasks)
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1729, in get
    return await self.request(
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1506, in request
    return await self.send(request, auth=auth, follow_redirects=follow_redirects)
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1593, in send
    response = await self._send_handling_auth(
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1621, in _send_handling_auth
    response = await self._send_handling_redirects(
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1658, in _send_handling_redirects
    response = await self._send_single_request(request)
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1695, in _send_single_request
    response = await transport.handle_async_request(request)
  File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 353, in handle_async_request
    resp = await self._pool.handle_async_request(req)
  File "/usr/local/lib/python3.9/contextlib.py", line 137, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 77, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ReadTimeout

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 191, in _async_refresh
    self.data = await self._async_update_data()
  File "/config/custom_components/bmw_connected_drive/coordinator.py", line 54, in _async_update_data
    await self.account.get_vehicles()
  File "/usr/local/lib/python3.9/site-packages/bimmer_connected/account.py", line 87, in get_vehicles
    self.vehicles.append(MyBMWVehicle(self, vehicle_dict))
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1975, in __aexit__
    await self._transport.__aexit__(exc_type, exc_value, traceback)
  File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 332, in __aexit__
    await self._pool.__aexit__(exc_type, exc_value, traceback)
  File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection_pool.py", line 326, in __aexit__
    await self.aclose()
  File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection_pool.py", line 312, in aclose
    raise RuntimeError(
RuntimeError: The connection pool was closed while 1 HTTP requests/responses were still in-flight.

Additional information

No response

@probot-home-assistant
Copy link

bmw_connected_drive documentation
bmw_connected_drive source
(message by IssueLinks)

@probot-home-assistant
Copy link

Hey there @gerard33, @rikroe, mind taking a look at this issue as it has been labeled with an integration (bmw_connected_drive) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@arboeh arboeh changed the title BMW Connected Drive permanentally closing connection BMW Connected Drive permanentally closes connection May 18, 2022
@BinnenBeest
Copy link

I have the same issue. Enjoying 🥹

@wokkeltje13
Copy link

seems like issue is solved now, probably an issue in the BMW backend (or maintenance)

@rssgonzalez
Copy link

For me, is also available again. it seems ok.

@wokkeltje13
Copy link

Think it is not stable, here it is not working anymore again.

@rssgonzalez
Copy link

Think it is not stable, here it is not working anymore again.

That's right! Unavailable again

@sdemmery
Copy link

Yep unavailable for me too. Removed the integration used the latest Beta via HACs now cant login at all. Only started playing as have been getting lots of unavailable messages triggering my badly coded NodeRed flows last few days was driving me crazy :-)

@Erisvaenget27
Copy link

Dosnt work for me as well. Quite sure its a BMW problem. Although its kind of funny the app is working? LOG saying: API error

@mimainka
Copy link

BMW is currently working on their backend. So it’s not a homeassistant issue.

@arboeh
Copy link
Author

arboeh commented May 19, 2022

API seems to run again, but I have still problem with disconnections.
It happens right now when this Log-Message occurs:

Logger: bimmer_connected.utils
Source: /usr/local/lib/python3.9/site-packages/bimmer_connected/utils.py:79
First occurred: 17:28:30 (54 occurrences)
Last logged: 19:30:06

DeprecationWarning:/config/custom_components/bmw_connected_drive/lock.py:87: 'VehicleStatus.door_lock_state' is deprecated. Please change to 'vehicle.doors_and_windows.door_lock_state'.
DeprecationWarning:/config/custom_components/bmw_connected_drive/lock.py:94: 'VehicleStatus.door_lock_state' is deprecated. Please change to 'vehicle.doors_and_windows.door_lock_state'.

The amount of occurrences makes me wonder...

@rikroe
Copy link
Contributor

rikroe commented May 19, 2022

Does it always happen if the DeprecationWarning is coming up?

I could be either BMW working on their servers and the requests taking longer (i.e. more than 10 seconds) or it could be httpx related (the library we use to call the API endpoints). I think I've seen some regression in one of their releases but have to find out if it is in the exact version that HA is using.

@rikroe
Copy link
Contributor

rikroe commented May 19, 2022

Ok, found the issue in httpx - it has been fixed, but not released yet:
PR for next release: encode/httpx#2214
PR that fixed the issue: encode/httpx#2156

I will try increasing the timeout to 30 seconds, maybe that helps for now if BMW servers are slow.

@rikroe
Copy link
Contributor

rikroe commented May 21, 2022

Actually it was wasn't only httpx, but also myself. This should be fixed by #71827.

@Mithrox
Copy link

Mithrox commented May 26, 2022

This issue above, does it also effect the integration function like on the screenshot below? The integration is working off and on through the day, and it results on the unknown/unavailable status like shown below.

image

@Mithrox
Copy link

Mithrox commented May 26, 2022

These are the errors I get over and over again

image

@uvjustin uvjustin mentioned this issue May 27, 2022
22 tasks
@rikroe
Copy link
Contributor

rikroe commented May 27, 2022

Yes, the unavailable state is a result of not being able to communicate with the API.
There are two reasons:

  • timeout issues with httpx and how we integrated it (which should be fixed with 2022.6)
  • 429 Too Many Requests is thrown by the BMW servers, I'll have to check the retry strategy in HA to somehow limit it

@arboeh
Copy link
Author

arboeh commented May 28, 2022

I can't login any more...

Screenshot_20220528-095835~2

@rikroe
Copy link
Contributor

rikroe commented May 28, 2022

BMW decided to block the specific user agent we were using, disableing the library completely.
There will be a release of the library today that fixes it (for now) which should get included in HA 2022.6.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants