Description
When the system is under memory pressure, headerToPayload seems to break, sending frames that causes the browser to close the connection. e.g. in chrome many different errors can appear such as:
WebSocket connection to 'ws://192.168.1.223:81/' failed: Received start of new message but previous message is unfinished.
attaching a test setup in this gist including a program to run on an ESP8266 and an html page to drive it:
https://gist.github.com/simap/6723beab8668035d19b9d7f8aea07b2e
Clicking connect, then on the "Test w headerToPayload" button allocates a buffer with an extra WEBSOCKETS_MAX_HEADER_SIZE
bytes, then writes offset by that, and calls sendBIN w/ headerToPayload true.
In the code, if fillSize is set to a small number reducing memory pressure, everything works OK.
This seems counterintuitive, since headerToPayload is supposed to reduce an extra malloc + memcpy in some cases.
It also breaks with some smaller payloads e.g.:
static const int blastSize = 256;