lexical-lsp / lexical

Lexical is a next-generation elixir language server
781 stars 77 forks source link

FIX: Invalid reads for requests that contain multi-byte characters #661

Closed scohen closed 3 months ago

scohen commented 3 months ago

We would get sporadic failures where the transport would keep reading headers after they were done. This was due to the previous request containing unicode characters at specific locations, which would confuse the transport, since it was reading the body of the request with IO.read, which reads characters, but it was passing in the content-length, which is counted in bytes. This would cause us to over-read the body, and consume part of the next body as we were reading the headers, and then the whole thing would fail when we tried to parse the headers.

The change is simple, switch to binread, which takes the number of bytes to read.

Moosieus commented 3 months ago

Looks good aside from the Dialyzer complaining about no return. Is there a good reason for using System.halt/0 over its more graceful System.stop/0 counterpart?

scohen commented 3 months ago

Is there a good reason for using System.halt/0 over its more graceful System.stop/0 counterpart?

Nope, changed it.