Reimplement zlib streaming.

This time with less bugs. It turned out that the crash was due to a
synchronisation issue between the pending reads and the actual shard
polling mechanism.

Essentially the pending reads would be cancelled via a simple bool but
there would still be a pass left and thus we would have a single
pending read left before or after running the polling mechanism and
this would cause a race condition.

Now the pending read mechanism is properly waited for before returning
control back to the caller.
This commit is contained in:
Rapptz
2017-10-14 21:17:27 -04:00
parent c3a727ac7e
commit 47a58d354d
3 changed files with 55 additions and 18 deletions

View File

@ -739,21 +739,29 @@ class HTTPClient:
return self.request(Route('GET', '/oauth2/applications/@me'))
@asyncio.coroutine
def get_gateway(self):
def get_gateway(self, *, encoding='json', v=6, zlib=True):
try:
data = yield from self.request(Route('GET', '/gateway'))
except HTTPException as e:
raise GatewayNotFound() from e
return data.get('url') + '?encoding=json&v=6'
if zlib:
value = '{0}?encoding={1}&v={2}&compress=zlib-stream'
else:
value = '{0}?encoding={1}&v={2}'
return value.format(data['url'], encoding, v)
@asyncio.coroutine
def get_bot_gateway(self):
def get_bot_gateway(self, *, encoding='json', v=6, zlib=True):
try:
data = yield from self.request(Route('GET', '/gateway/bot'))
except HTTPException as e:
raise GatewayNotFound() from e
if zlib:
value = '{0}?encoding={1}&v={2}&compress=zlib-stream'
else:
return data['shards'], data['url'] + '?encoding=json&v=6'
value = '{0}?encoding={1}&v={2}'
return data['shards'], value.format(data['url'], encoding, v)
def get_user_info(self, user_id):
return self.request(Route('GET', '/users/{user_id}', user_id=user_id))