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

Fix error when trying to convert text message partial payload to UTF-8 #788

Merged
merged 1 commit into from
Jun 21, 2020

Conversation

SemyonBaryshev
Copy link
Contributor

There was an issue with "not valid UTF-8 data" error being returned sometimes for incoming text messages that were split into multiple frames. If incoming text message consists of multiple frames, buffered partial payload may not necessarily represent a valid UTF-8 string, only a whole received message must represent a valid UTF-8 string. So we have to check if buffered payload of text message can be converted to a UTF-8 string only after receiving all frames of incoming text message, and only then try to convert to UTF-8 string and return error if it was not valid.

@daltoniam
Copy link
Owner

Thanks! Makes sense. Appreciate the fix.

@daltoniam daltoniam merged commit 51b6c78 into daltoniam:master Jun 21, 2020
@sjmueller
Copy link

Can this same error happen with the native engine using URLSession.webSocketTask? I have a scenario using the native websocket that sometimes results in this error receiving a large payload:

2020-07-09 16:19:35.522322-0700 [] nw_protocol_copy_ws_definition_block_invoke [C2.1:5] received invalid utf-8 sequence
2020-07-09 16:19:35.523424-0700 [] nw_read_request_report [C2] Receive failed with error "Bad address"
2020-07-09 16:19:35.524531-0700 Connection 2: received failure notification
2020-07-09 16:19:35.525757-0700 [] nw_read_request_report [C2] Receive failed with error "Socket is not connected"
2020-07-09 16:19:35.526124-0700 [] nw_content_context_copy_protocol_metadata called with null context
2020-07-09 16:19:35.526408-0700 [] nw_content_context_copy_protocol_metadata called with null context, dumping backtrace:
        [arm64] libnetcore-1880.120.4
    0   libnetwork.dylib                    0x00000001b03fbe80 __nw_create_backtrace_string + 120
    1   libnetwork.dylib                    0x00000001affe93d8 nw_content_context_copy_protocol_metadata + 548
    2   CFNetwork                           0x00000001b11b30b0 _CFHTTPServerResponseEnqueue + 29872
    3   libdispatch.dylib                   0x00000001065a9d10 _dispatch_call_block_and_release + 32
    4   libdispatch.dylib                   0x00000001065ab18c _dispatch_client_callout + 20
    5   libdispatch.dylib                   0x00000001065b2968 _dispatch_lane_serial_drain + 724
    6   libdispatch.dylib                   0x00000001065b35b4 _dispatch_lane_invoke + 492
    7   libdispatch.dylib                   0x00000001065bf0f0 _dispatch_workloop_worker_thread + 1344
    8   libsystem_pthread.dylib             0x00000001ada4b714 _pthread_wqthread + 276
    9   libsystem_pthread.dylib             0x00000001ada519c8 start_wqthread + 8
2020-07-09 16:19:35.527667-0700 Blink[32470:8174263] [websocket] Read completed with an error Socket is not connected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants