git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Intermittent bug with asyncio and MS Edge


Hi all

I have a strange intermittent bug.

The role-players -
     asyncio on Python 3.8 running on Windows 10
     Microsoft Edge running as a browser on the same machine

The bug does not occur with Python 3.7.
It does not occur with Chrome or Firefox.
It does not occur when MS Edge connects to another host on the network, 
running the same Python program (Python 3.8 on Fedora 31).

The symptoms -
     On receiving a connection, I send an HTML page to the browser,
         which has 20 lines like this -

     <script type="text/javascript" src="src/main.js"></script>
     <script type="text/javascript" src="src/on_load.js"></script>
     ...

Intermittently, one or other of the script files is not received by MS Edge.

I have checked the Network tab in Developer Tools in MS Edge. It shows 
the first few requests getting a Status 200 OK, then some are shown as 
'Pending'. This seems to be where the problem occurs.

I am hoping that someone can give me some hints about how to debug this.

My function to send the script file looks like this -

     async def send_file(writer, fname):

         status = 'HTTP/1.1 200 OK\r\n'
         writer.write(status.encode())

         headers = []
         headers.append(('CONNECTION', 'keep-alive'))
         headers.append(('DATE',
             email.utils.formatdate(usegmt=True)))
         headers.append(('SERVER',
            f'Python {sys.version.split()[0]} asyncio'))
         headers.append(('Content-type', 'text/javascript'))
         headers('Transfer-Encoding', 'chunked'))
         for key, val in headers:
             writer.write(f'{key}: {val}\r\n'.encode())
         writer.write('\r\n'.encode())
         await writer.drain()

         with open(fname 'rb') as fd:
             chunk = fd.read(8192)
             while chunk:
                 writer.write(hex(len(chunk))[2:].encode() + b'\r\n')
                 writer.write(chunk + b'\r\n')
                 await writer.drain()
                 chunk = fd.read(8192)
             writer.write(b'0\r\n\r\n')
             await writer.drain()

         writer.close()
         await writer.wait_closed()

I have asked the same question on StackOverflow, from an MS Edge 
perspective -
 
https://stackoverflow.com/questions/60785767/ms-edge-randomly-does-not-load-script

I don't know whether the problem lies with Python or MS Edge, but as it 
does not happen with Python 3.7, I am suspecting that something changed 
in 3.8 which does not match MS Edge's expectations.

Any hints much appreciated.

Frank Millman