Search Unity

Best HTTP Released

Discussion in 'Assets and Asset Store' started by BestHTTP, Sep 11, 2013.

  1. hermit_021

    hermit_021

    Joined:
    May 31, 2018
    Posts:
    6
    @BestHTTP Hi, I'm using best http 2 for my game. There is strange issue in receiving broadcast.
    There are 2 players on the table when 2nd player joins the table for the first time he doesn't get any broadcast he has to rejoin the table but 1st player gets all broadcast he doesn't have to rejoin.
     
  2. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @hermit_021

    It would be very valuable to know what protocol are you using (socket.io, signalr, etc.), and how do you send your broadcasts.
     
  3. hermit_021

    hermit_021

    Joined:
    May 31, 2018
    Posts:
    6

    @BestHTTP, I'm using socket.io. and let me describe it bit more. as I said second player is not getting broadcast but the case is, there are two classes for both i have subscribe the broadcast in onenable one of them is called but not the other one. Both are active in scene in debug i get logs for onenable method from both classes from both players but both methods of that broadcast is called for 1st joined player only 2nd player have to rejoin in order to get call both methods.
     
  4. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
  5. hermit_021

    hermit_021

    Joined:
    May 31, 2018
    Posts:
    6
    upload_2022-10-13_16-13-4.png

    upload_2022-10-13_16-13-25.png

    Both game objects are active and both scripts are also enabled.
     
  6. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @hermit_021 I couldn't replicate your issue, and in this case verbose logging wouldn't help as On and Off cals aren't logged. So could you send a minimal repro project?

    Also, please note that calling Off removes all callbacks for that event name!
     
  7. gawoon

    gawoon

    Joined:
    Dec 11, 2017
    Posts:
    9
    @BestHTTP
    hi, here's my context.
    i'm using socketio3 to send my webcamtexture to python server.
    i have a texture which has a resolution about 640x480, and i encoded it to JPG format, and then send it through socketio.
    i profiled with my tablet Lenovo P11, and i'd like to know how to optimize this.
    it seems that zlib take a lot of time.
    is there way not to compress my data before sending?
    any other solution will save me
    thanks in advance.
    upload_2022-11-3_2-19-8.png
     

    Attached Files:

  8. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @gawoon The new version in the works can help solving it by
    1. giving a way to disable websocket extensions
    2. moving extension and websocket frame creation to the sender thread

    In your case both will be helpful as JPG already a compressed format, further compression can be only a waste of CPU time, so disabling the per-message deflate extension is a good step to consume less cpu.

    If you drop me a mail at besthttp@gmail.com i can send a package with the new version.
     
    choigw likes this.
  9. choigw

    choigw

    Joined:
    Jul 21, 2020
    Posts:
    4
    awesome!
    here's my email, choigawoon@gmail.com
    also wonder if when do you think new version is released on the package manager?
    oops, i sent the mail to you also.
     
  10. gawoon

    gawoon

    Joined:
    Dec 11, 2017
    Posts:
    9
    hi again.
    your solution work perfectly. thanks a lot!
    before about 100ms -> now about 1-2ms upload_2022-11-4_8-6-41.png
     
    BestHTTP likes this.
  11. 1002711414

    1002711414

    Joined:
    Dec 16, 2021
    Posts:
    1
    Hello,How to Authentication by password and username?
     
  12. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
  13. JosephEgens

    JosephEgens

    Joined:
    May 5, 2020
    Posts:
    3
    @BestHTTP
    Hello,
    I have been experiencing a problem with the BestHTTP package for some time, on some Android devices the HTTPRequest functions and requests with SignalR (HubConnection when sending) crash the application. I did several tests but the application crashes without any particular message on the Play Store (except a SIGBUS and SIGSEGV message and more recently a "[libil2cpp.so] BestHTTP47.cpp - FastChaCha7539Engine_DoFinal_mB94251F11244EE9C50414238F8C1CF04D467191A" message related to a SIGBUS error). I changed the HTTPRequest functions to UnityWebRequest and it works but I haven't found an alternative for SignalR.

    (I would like to point out that this crash only happens to 1% of our users and they all use a Samsung Galaxy A13)

    Thanks in advance for your help!

    Edit : I'm using Unity 2021.3.16f1
     
  14. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @JosephEgens What version of the plugin and Unity are you using?
     
  15. JosephEgens

    JosephEgens

    Joined:
    May 5, 2020
    Posts:
    3
    I'm using Unity 2021.3.16f1 and BestHTTP/2 V 2.8.2
     
  16. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @JosephEgens I saw nothing suspicious in the FastChaCha7539Engine's DoFinal method, however under Unity 2021.2 or newer it uses BouncyCastle's new Span based APIs.
    Drop me a mail at besthttp@gmail.com (or you can join to the plugin's discord server and send a private message) and will send a new package that will disable the Span based APIs so we can see whether it makes any change.
     
  17. JosephEgens

    JosephEgens

    Joined:
    May 5, 2020
    Posts:
    3
    Hello,
    Thank you for your reactivity, with the plugin that you sent me, the requests do not cause any more crashes and work properly.
    Thank you again for your help !
     
    minthiha and BestHTTP like this.
  18. darydol

    darydol

    Joined:
    May 19, 2017
    Posts:
    9
    I made it as an echo server with WebsocketSharp, and made it as a BestHTTP.WebSocket client and tested it, but the following error occurred.
    This is for a simple test to send and receive 38,553 bytes. please tell me how to solve it
    Request Finished with Error! Exception: TCP Stream closed unexpectedly by the remote server
    at BestHTTP.WebSocket.Frames.WebSocketFrameReader.ReadByte (System.IO.Stream stream) [0x00010] in G:\T01\Assets\Best HTTP\Source\WebSocket\Frames\WebSocketFrameReader.cs:181
    at BestHTTP.WebSocket.Frames.WebSocketFrameReader.Read (System.IO.Stream stream) [0x00001] in G:\T01\Assets\Best HTTP\Source\WebSocket\Frames\WebSocketFrameReader.cs:60
    at BestHTTP.WebSocket.WebSocketResponse.ReceiveThreadFunc () [0x00011] in G:\T01\Assets\Best HTTP\Source\WebSocket\WebSocketResponse.cs:402
     
  19. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @darydol What version of the plugin are you using? You can check it by printing out HTTPManager.UserAgent (or just check it in the source).
     
  20. Serhii-Horun

    Serhii-Horun

    Joined:
    Apr 12, 2015
    Posts:
    151
    Hi @BestHTTP !
    We have a question regarding your TLS plugin.
    Can't we get any problem with security if anybody on Android can access the folder where you store the metadata? Any sensitive data there?
     

    Attached Files:

  21. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
  22. unity_ci

    unity_ci

    Joined:
    Oct 31, 2019
    Posts:
    1
    Hi @BestHTTP.
    When I try to make an HTTP/2 GET request on the device with the Turkish language as a default, it is declined by the server. The client error is
    Code (CSharp):
    1. Exception: System.Exception: RST_STREAM frame received! Error code: PROTOCOL_ERROR(1)
    The server error is invalid_headers.

    The headers from Charles are provided in the image below, and two of the headers have strange symbols instead of the letter "I". I do not modify these 2 headers anywhere in my app, but I see that they are used in the BestHttp plugin. Do you know how I can fix this?
     

    Attached Files:

    Last edited: Mar 27, 2023
  23. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @unity_ci
    Thanks for the details! The plugin used ToLower instead of ToLowerInvariant in a few places. Sent a link to an updated package in private.
     
    unity_ci likes this.
  24. waldgeist

    waldgeist

    Joined:
    May 6, 2017
    Posts:
    388
    Hey BestHTTP team, we're devloping an AR app that initially loads textures over HTTP to put them on objects around you. We implemented a job system that schedules the texture downloads based on how close those objects are to the user, so not all of them are being loaded at once.

    We were still seeing frame drops when using Unity's texture download, so we switched to BestHTTP's download implemention hoping that we can get rid of these frame drops as it is multi-threaded.

    However, we noticed that the frame drops still occur. When profiling, we saw that in each performance spike around 95% of the time is spent on the HTTPUpdateDelegator. Below that node, we see a lot of GC.Alloc calls for around 62mb of data. Is there any chance to speed up things here?

    EDIT: The problem was caused by another library which I called in the callback. So all good, sorry for bothering.
     
    Last edited: Apr 3, 2023
  25. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @waldgeist

    HTTPUpdateDelegator is the link between the plugin and Unity. Its Update function is called by Unity, and that's where all the callbacks are called. Because of this, everyhing you do in the HTTPRequest's callback will be show up under HTTPUpdateDelegator in the profiler.
    Also, all memory for the downloaded content is allocated outside of the Unity main thread, if you access the content through HTTPResponse's Data property, the plugin doesn't allocate any additonal memory. If you use DataAsTexture2D, then the plugin only creates the Texture2D:
    Code (CSharp):
    1. public Texture2D DataAsTexture2D
    2. {
    3.     get
    4.     {
    5.         if (Data == null)
    6.             return null;
    7.  
    8.         if (texture != null)
    9.             return texture;
    10.  
    11.         texture = new Texture2D(0, 0, TextureFormat.RGBA32, false);
    12.         texture.LoadImage(Data, true);
    13.  
    14.         return texture;
    15.     }
    16. }
    The plugin also has an internal BufferPool to reuse allocated byte[]s, and there's a very high chance that after the first download the plugin only allocates memory for the final downloaded content (except the headers of course).
     
  26. Ludogram

    Ludogram

    Joined:
    May 17, 2019
    Posts:
    2
    Hello, sorry to bother but it seems I'm having some issue with BestHTTP when my Managed Stripping Level is set to minimal. When it's on disabled everything is working fine but when it's on minimum I'm getting this error :

    Unfortunately since we are releasing our project on IL2CPP plateform we can't disable Managed Stripping Level.
    I've tried putting BestHTTP and other things in a link.xml file to prevent them for being stripped but it didn't work.

    Code (csharp):
    1. <linker>
    2.   <assembly fullname="System">
    3.     <type fullname="System" preserve="all" />
    4.   </assembly>
    5.   <assembly fullname="UnityEngine">
    6.     <type fullname="UnityEngine" preserve="all" />
    7.   </assembly>
    8.   <assembly fullname="BestHTTP">
    9.     <type fullname="BestHTTP" preserve="all" />
    10.   </assembly>
    11. </linker>
    It might come from a different script being stripped but at this point I'm stuck and only see this.
     
  27. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @Ludogram

    The exception happened in MMatchmaking.Match (DirectoryGame game, System.Boolean host) [0x0002d] in C:\\[path]\\MMatchmaking.Command.cs:22 \r\n at MMatchmaking.<_NewOnlineGame>b__55_0 (BestHTTP.HTTPRequest req, BestHTTP.HTTPResponse res) [0x00034] in C:\\[path]\\MMatchmaking.Directory.cs:128.

    You might have to add a few of your own classes too (like DirectoryGame, _NewOnlineGame, etc.) to preserve by managed stripping.
     
  28. Ludogram

    Ludogram

    Joined:
    May 17, 2019
    Posts:
    2
    @BestHTTP thanks for the quick answer.

    Unfortunately, I used the attribute [UnityEngine.Scripting.Preserve] in several script and I'm getting the same error.
    I used it in : RequestEvents, HTTPUpdateDelegator, HTTPManager and two personnal script that are in the error, MMatchmaking.Directory and MMatchmaking.Command (which include MMatchmaking.Match)
     
  29. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @Ludogram The plugin doesn't require any more Preserve attributes, it already have it where would problems.

    The exception happens in a HTTPRequest callback where most probably you try to parse the downloaded content (json). I don't know what's your classes look like, so i can't help too much, but you might have to add Preserve to fields/properties too. Or alternately, add the assembly+namespace to the link.xml.
     
  30. vuthang

    vuthang

    Joined:
    Mar 7, 2017
    Posts:
    50
    Hi, How I can set websocket No Delay? I see webSocket.InternalRequest.TryToMinimizeTCPLatency is removed
     
  31. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @vuthang The plugin sets NoDelay for all TCP connection. WebSocket frames are sent out as soon as possible.
     
    vuthang likes this.
  32. hermit_021

    hermit_021

    Joined:
    May 31, 2018
    Posts:
    6
    @BestHTTP


    Socket connection issue in carrier network
    we are using this plugin for multiplayer game and from last 3 days we found socket connection issue in Reliance JIO carrier in India
    i am doing socket connection but socket is not connected to that server for JIO carrier rest carrier it works fine
    so can you please help out for same to resolve
    as we have try to connect with socket io version 2 and version 3 both
    but not works

    awaiting for response

    Thanks
     
  33. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    hermit_021 likes this.
  34. virtouso

    virtouso

    Joined:
    Jul 12, 2013
    Posts:
    60
    is it possible to have a signalr server in unity? i need to make my clients directly connect to server that can run unity features.
     
  35. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
  36. gnt-hungvt

    gnt-hungvt

    Joined:
    Mar 21, 2023
    Posts:
    1
    Hi, I can connect to socket.io with my code and store all socket namespaces into a dictionary, at some point I want disconnect a single namespace by calling the code sockets[namespace].Off() and sockets[namespace].Disconnect() but when I do that the OnDisconnected callback is not fired. Is this normal? Am I doing it the right way? thanks
     
  37. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @gnt-hungvt

    Off removes all subscription for that namespace, so if you call it first, it will remove any callback you set to handle disconnects.

    So, you should call Off() to remove all callbacks, then you can subscribe to disconnect events and then call the Disconnect itself:
    Code (CSharp):
    1. sockets[nsp].Off();
    2. sockets[nsp].Once("disconnect", OnDisconnected);
    3. sockets[nsp].Disconnect();
     
  38. d_sharov

    d_sharov

    Joined:
    Dec 24, 2021
    Posts:
    23
    @BestHTTP Hi

    Some of our players started getting native crashes. The stacktrace refers to the plugin.
    Can you advise something in this regard?

    Native StackTrace:
    Thread 0 (crashed)
    0 libil2cpp.so 0x000000761b4b785c FastGcmBlockCipher_Tables8kGcmMultiplier_MultiplyH_m0020F789B9B9B5F37BA04B1E6252299F7C674078 (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\BestHTTP__48.cpp:20379)
    1 libil2cpp.so 0x000000761b4b76a8 FastGcmBlockCipher_ProcessBytes_mD8524AC266A70AF03CE06328EC0C4125DB0FA25E (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\BestHTTP__48.cpp:18296)
    2 libil2cpp.so 0x000000000232dea4 (unknown) (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\BestHTTP__49.cpp:239)
    3 libil2cpp.so 0x000000761b4bbebc FastTlsAeadCipherImpl_DoFinal_mBA11E1F4343B59C47D1FF1977DD9200FD5F4E1C4 (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\BestHTTP__49.cpp:6983)
    4 libil2cpp.so 0x000000000232d248 (unknown) (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\BestHTTP__49.cpp:239)
    5 libil2cpp.so 0x000000761b4bb260 FastTlsAeadCipher_DecodeCiphertext_m7898C39D9FC3B6D02F39EEC94773C65B8BFD9A60 (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\BestHTTP__49.cpp:6047)
    6 libil2cpp.so 0x0000000002397bd0 (unknown) (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\BestHTTP__7.cpp:228)
    7 libil2cpp.so 0x000000761b525bec RecordStream_DecodeAndVerify_mD32BBC2A3B3B88721F1D8F5B9BC348FBBD1EF8BE (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\BestHTTP__7.cpp:23044)
    8 libil2cpp.so 0x000000761b525dd0 RecordStream_ReadRecord_m2A15BA0845BCEA35607C333B4A81FAC48A475540 (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\BestHTTP__7.cpp:22954)
    9 libil2cpp.so 0x000000761b5416cc TlsProtocol_SafeReadRecord_mCACA20C9D9C2DA65EDAB4FF086847DE4FC6F5FED (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\BestHTTP__8.cpp:14887)
    10 libil2cpp.so 0x00000000023b32d0 (unknown) (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\BestHTTP__8.cpp:20)
    11 libil2cpp.so 0x000000761b5412d0 TlsProtocol_ReadApplicationData_m18F18076098496E198EA0091DC1605DEF0D5A70C (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\BestHTTP__8.cpp:14658)
    12 libil2cpp.so 0x0000000002337b60 (unknown) (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\BestHTTP__49.cpp:86)
    13 libil2cpp.so 0x000000761b4c5b68 HTTP2FrameHelper_StreamRead_m76572EEDDF7D01008AD5AC7531E90B6CC80016AE (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\BestHTTP__49.cpp:15207)
    14 libil2cpp.so 0x000000761b4c5dc8 HTTP2FrameHelper_ReadHeader_m81C22DBF470F131ABD1EE729E1BF7BA43733A54C (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\BestHTTP__49.cpp:15361)
    15 libil2cpp.so 0x000000761b4cc6bc HTTP2Handler_ReadThread_m3683CCFADC0C478E3FDCB2872AE8BADE3A87E9A0 (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\BestHTTP__49.cpp:20610)
    16 libil2cpp.so 0x0000000003b80f38 ContextCallback_Invoke_m872CCCD40428B88C2612772491BE5157895B5F61_inline (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\mscorlib__8.cpp:31107)
    17 libil2cpp.so 0x000000761cd0ef3c ExecutionContext_RunInternal_mC37E85D6FC972DF219A00FE1EE34329D1D63CC94 (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\mscorlib__8.cpp:24852)
    18 libil2cpp.so 0x000000761af6c754 il2cpp::vm::Runtime::InvokeWithThrow(MethodInfo const*, void*, void**)
    19 libil2cpp.so 0x000000761af6c6a0 il2cpp::vm::Runtime::Invoke(MethodInfo const*, void*, void**, Il2CppException**)
    20 libil2cpp.so 0x000000761afbacb4 ThreadStart (C:/Program Files/Unity/Editor/Data/il2cpp/libil2cpp/icalls/mscorlib/System.Threading\Thread.cpp:64)
    21 libil2cpp.so 0x000000761afad3fc il2cpp::eek:s::Thread::RunWrapper(void*)
    22 libil2cpp.so 0x000000761af26334 il2cpp::eek:s::ThreadImpl::ThreadStartWrapper(void*)
    23 libc.so 0x00000076bfbc6968 <symbols missing for uuid: 2e80c8d2a1177add8d9802d2d22ade15>
    24 libc.so 0x00000076bfb6ea30 <symbols missing for uuid: 2e80c8d2a1177add8d9802d2d22ade15>
     
  39. yuliyF

    yuliyF

    Joined:
    Nov 15, 2012
    Posts:
    197
    @BestHTTP, Hi, I'm using a simple https connections ( UnityWebRequest.Post) with my PHP server. It's work fine. Can you explain me the benefits of your plugin. Thanks.
     
  40. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @d_sharov Are all crashes have the same stack trace?
     
  41. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @yuliyF If you use only POST requests, the plugin might not have much advantage over UnityWebRequest. Automatic cookie handling and better control over trusted certificates, client certificates with the security addons come into my mind first.
     
    yuliyF likes this.
  42. d_sharov

    d_sharov

    Joined:
    Dec 24, 2021
    Posts:
    23
    @BestHTTP
    No. It happens differently, but appears in many BestHTTP__48

    Debug symbols have been loaded into the latest version.
    Here's what we got.
    The crash was reproduced at the start of the application.
    We download the art, which we then use in the client's UI.
    Native StackTrace:
    Thread 0 (crashed)
    0 libil2cpp.so 0x00000071e667d8a4 GC_gcj_vector_proc (C:/Program Files/Unity/Editor/Data/il2cpp/libil2cpp/gc\BoehmGC.cpp:78)
    1 libil2cpp.so 0x00000071e66cc1d4 GC_mark_from (C:/Program Files/Unity/Editor/Data/il2cpp/external/bdwgc/extra/..\mark.c:795)
    2 libil2cpp.so 0x00000071e66c8d28 GC_mark_some (C:/Program Files/Unity/Editor/Data/il2cpp/external/bdwgc/extra/..\mark.c:0)
    3 libil2cpp.so 0x00000071e66c8adc GC_collect_a_little_inner (C:/Program Files/Unity/Editor/Data/il2cpp/external/bdwgc/extra/..\alloc.c:672)
    4 libil2cpp.so 0x00000071e66cc950 GC_alloc_large (C:/Program Files/Unity/Editor/Data/il2cpp/external/bdwgc/extra/..\malloc.c:56)
    5 libil2cpp.so 0x00000071e66ca8c0 GC_generic_malloc (C:/Program Files/Unity/Editor/Data/il2cpp/external/bdwgc/extra/..\malloc.c:264)
    6 libil2cpp.so 0x00000071e66cccc4 GC_malloc_kind_global (C:/Program Files/Unity/Editor/Data/il2cpp/external/bdwgc/extra/..\malloc.c:327)
    7 libil2cpp.so 0x00000071e6686010 il2cpp::vm::Array::NewSpecific(Il2CppClass*, unsigned long)
    8 libil2cpp.so 0x00000071e6c26644 Record_Resize_mB06904D84D6F1DF20EC60D26DF47752BCBBAE873 (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\BestHTTP__7.cpp:23807)
    9 libil2cpp.so 0x00000071e6c25f0c Record_ReadFragment_m01CCBA2900E99919A9138369544D94DFC7917C01 (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\BestHTTP__7.cpp:23670)
    10 libil2cpp.so 0x00000071e6c25d00 RecordStream_ReadRecord_m2A15BA0845BCEA35607C333B4A81FAC48A475540 (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\BestHTTP__7.cpp:22896)
    11 libil2cpp.so 0x00000071e6c4165c TlsProtocol_SafeReadRecord_mCACA20C9D9C2DA65EDAB4FF086847DE4FC6F5FED (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\BestHTTP__8.cpp:14887)
    12 libil2cpp.so 0x00000000023fe260 (unknown) (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\BestHTTP__8.cpp:20)
    13 libil2cpp.so 0x00000071e6c41260 TlsProtocol_ReadApplicationData_m18F18076098496E198EA0091DC1605DEF0D5A70C (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\BestHTTP__8.cpp:14658)
    14 libil2cpp.so 0x0000000002382904 (unknown) (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\BestHTTP__49.cpp:86)
    15 libil2cpp.so 0x00000071e6bc590c HTTP2FrameHelper_StreamRead_m76572EEDDF7D01008AD5AC7531E90B6CC80016AE (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\BestHTTP__49.cpp:15207)
    16 libil2cpp.so 0x00000071e6bc5b6c HTTP2FrameHelper_ReadHeader_m81C22DBF470F131ABD1EE729E1BF7BA43733A54C (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\BestHTTP__49.cpp:15361)
    17 libil2cpp.so 0x00000071e6bcc494 HTTP2Handler_ReadThread_m3683CCFADC0C478E3FDCB2872AE8BADE3A87E9A0 (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\BestHTTP__49.cpp:20612)
    18 libil2cpp.so 0x0000000003c40be4 ContextCallback_Invoke_m872CCCD40428B88C2612772491BE5157895B5F61_inline (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\mscorlib__8.cpp:31373)
    19 libil2cpp.so 0x00000071e8483be8 ExecutionContext_RunInternal_mC37E85D6FC972DF219A00FE1EE34329D1D63CC94 (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\mscorlib__8.cpp:25089)
    20 libil2cpp.so 0x00000071e6664d20 il2cpp::vm::Runtime::InvokeWithThrow(MethodInfo const*, void*, void**)
    21 libil2cpp.so 0x00000071e6664c6c il2cpp::vm::Runtime::Invoke(MethodInfo const*, void*, void**, Il2CppException**)
    22 libil2cpp.so 0x00000071e66a94f4 ThreadStart (C:/Program Files/Unity/Editor/Data/il2cpp/libil2cpp/icalls/mscorlib/System.Threading\Thread.cpp:62)
    23 libil2cpp.so 0x00000071e6638bdc il2cpp::eek:s::Thread::RunWrapper(void*)
    24 libil2cpp.so 0x00000071e66aa148 il2cpp::eek:s::ThreadImpl::ThreadStartWrapper(void*)
    25 libc.so 0x0000007316d49a08 <symbols missing for uuid: e9653d1f6c173c6b86b171a5be6af6eb>
    26 libc.so 0x0000007316ce327c <symbols missing for uuid: e9653d1f6c173c6b86b171a5be6af6eb>

    Perhaps we are somehow using the request incorrectly
    Code (CSharp):
    1. private async UniTask<byte[]> DownloadAsync(string url, string uniqueHash, CancellationToken cancellationToken)
    2.         {
    3.             var attempts = ATTEMPTS;
    4.             var uri = new Uri(url);
    5.             while (Application.isPlaying)
    6.             {
    7.                 cancellationToken.ThrowIfCancellationRequested();
    8.  
    9.                 if (attempts <= 0 || !Application.isPlaying)
    10.                     return Array.Empty<byte>();
    11.  
    12.                 var request = new HTTPRequest(uri);
    13.                 request.Timeout = timeout;
    14.                 var response = await request.GetHTTPResponseAsync(cancellationToken);
    15.                 if (response.IsSuccess)
    16.                 {
    17.                     var result = response.Data ?? Array.Empty<byte>();
    18.                     WriteCache(filePath + uniqueHash, result);
    19.                     return result;
    20.                 }
    21.  
    22.                 --attempts;
    23.             }
    24.  
    25.             throw new OperationCanceledException("Data not downloaded!");
    26.         }
     
  43. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @d_sharov Nothing wrong with your code, i think that will be a bug in Unity.
    What version of Unity are you using? What platforms you experience these? Would it be possible to create a repro-project?
    Do you do any scene loading during the crash? I'm currently preparing a bug report that freezes the application under Android if a few thread doing GC intensive work during scene loading.
     
  44. d_sharov

    d_sharov

    Joined:
    Dec 24, 2021
    Posts:
    23
    @BestHTTP
    Unity: 2022.3.5f1 lts
    Most crashes happen on android.
    To work with asynchrony, we use a Unitask, including requests for downloading art. No more than 6 requests in parallel.

    At startup, when we load the startup scene, in which there is only a loading screen.
    This scene already loads the main scene, in which, upon Initialize(IInitializable from Zenject), the download of arts in the background starts.
    Also, among other things, we send requests to receive the application configuration and initialization of other SDKs
    We had a suspicion of the garbage collector, so in the new version we switched the setting to gcIncremental = false.

    In the current situation, we expect that the Unitask does not allow running multiple threads, so all downloads must go to the Player loop in one thread. Or will running BestHTTP requests still create new threads?
    If so, how can I turn it off?
     
  45. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @d_sharov The one that i'm investigating/preparing the repro project, switching between GC implementations doesn't help.

    The plugin does create threads to send the requests and receive the response. If the server can handle http/1.1 only, at most 6 connections are used per host-variant and each connection uses one thread.
    If the server capable of HTTP/2, the plugin uses only one connection, but two threads (one for sending and one for receiving). Your first stacktrace has an entry for HTTP2, so if all requests are sent to the same server, only two threads are started.
    As far as i know, Unity starts a shared socket poll thread too.

    It's not possible to disable thread usage in the plugin.
     
  46. d_sharov

    d_sharov

    Joined:
    Dec 24, 2021
    Posts:
    23
    @BestHTTP
    Noticed this feature.
    When testing the apk build - did not catch crashes at all.
    At the same time, when the tests were transferred to Google Play (internal testing), they immediately began to receive them again.

    Do you have any progress in learning this?
    We have a very high crash rate.
    Up to 40% of our users get these errors.
    Will switching to a pure Unity Web Request help with this issue? Can an addressable be used to get assets?

    Native StackTrace:
    Thread 0 (crashed)
    0 libil2cpp.so 0x000000755b46efc0 il2cpp::vm::Class::Init(Il2CppClass*)
    1 libil2cpp.so 0x000000755b46fa28 il2cpp::vm::Class::IsAssignableFrom(Il2CppClass*, Il2CppClass*)
    2 libil2cpp.so 0x000000755b445b70 il2cpp::vm::Object::IsInst(Il2CppObject*, Il2CppClass*)
    3 libil2cpp.so 0x000000755cfc0128 StringBuilder_AppendFormatHelper_mB721541560403777C9190F76D162C918A9A840D1 (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\mscorlib__10.cpp:7998)
    4 libil2cpp.so 0x000000755cfb419c String_FormatHelper_m9D0E826CCC406EADF91AF3B83FBC5DD012C81192 (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\mscorlib__1.cpp:22982)
    5 libil2cpp.so 0x000000755cfb423c String_Format_mFB7DA489BD99F4670881FF50EC017BFB0A5C0987 (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\mscorlib__1.cpp:22781)
    6 libil2cpp.so 0x000000755b943a24 ConnectionBase_ToString_mAF0DF47C500C7D8D080132E443EF6F48F6BF8880 (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\BestHTTP__47.cpp:25525)
    7 libil2cpp.so 0x0000000002339ec8 (unknown) (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\BestHTTP__48.cpp:75)
    8 libil2cpp.so 0x000000755b945ecc HTTP1Handler_RunHandler_mAABE7663E7CD91B776FD0D69B5795E6786F60FD1 (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\BestHTTP__48.cpp:3479)
    9 libil2cpp.so 0x000000000233b890 (unknown) (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\BestHTTP__48.cpp:118)
    10 libil2cpp.so 0x000000755b947894 HTTPConnection_ThreadFunc_mE79EAE3CE7AEE073E71DCC2506B7BF6F34996340 (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\BestHTTP__48.cpp:4856)
    11 libil2cpp.so 0x0000000003b93dc0 ContextCallback_Invoke_m872CCCD40428B88C2612772491BE5157895B5F61_inline (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\mscorlib__8.cpp:31373)
    12 libil2cpp.so 0x000000755d19fdc4 ExecutionContext_RunInternal_mC37E85D6FC972DF219A00FE1EE34329D1D63CC94 (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\mscorlib__8.cpp:25089)
    13 libil2cpp.so 0x000000755b424480 il2cpp::vm::Runtime::InvokeWithThrow(MethodInfo const*, void*, void**)
    14 libil2cpp.so 0x000000755b4243cc il2cpp::vm::Runtime::Invoke(MethodInfo const*, void*, void**, Il2CppException**)
    15 libil2cpp.so 0x000000755b4686bc ThreadStart (C:/Program Files/Unity/Editor/Data/il2cpp/libil2cpp/icalls/mscorlib/System.Threading\Thread.cpp:62)
    16 libil2cpp.so 0x000000755b3f84cc il2cpp::eek:s::Thread::RunWrapper(void*)
    17 libil2cpp.so 0x000000755b46930c il2cpp::eek:s::ThreadImpl::ThreadStartWrapper(void*)
    18 libc.so 0x00000076b12eea08 <symbols missing for uuid: e9653d1f6c173c6b86b171a5be6af6eb>
    19 libc.so 0x00000076b128827c <symbols missing for uuid: e9653d1f6c173c6b86b171a5be6af6eb>

    Native StackTrace:
    Thread 0 (crashed)
    0 libil2cpp.so 0x00000077da49589c GC_is_marked (C:/Program Files/Unity/Editor/Data/il2cpp/external/bdwgc/extra/..\mark.c:242)
    1 libil2cpp.so 0x00000077da49465c GC_finalize (C:/Program Files/Unity/Editor/Data/il2cpp/external/bdwgc/extra/..\finalize.c:1058)
    2 libil2cpp.so 0x00000077da4938f4 GC_finish_collection (C:/Program Files/Unity/Editor/Data/il2cpp/external/bdwgc/extra/..\alloc.c:1084)
    3 libil2cpp.so 0x00000077da493334 GC_try_to_collect_inner (C:/Program Files/Unity/Editor/Data/il2cpp/external/bdwgc/extra/..\alloc.c:592)
    4 libil2cpp.so 0x00000077da495444 GC_collect_or_expand (C:/Program Files/Unity/Editor/Data/il2cpp/external/bdwgc/extra/..\alloc.c:1484)
    5 libil2cpp.so 0x00000077da497aa4 GC_alloc_large (C:/Program Files/Unity/Editor/Data/il2cpp/external/bdwgc/extra/..\malloc.c:64)
    6 libil2cpp.so 0x00000077da495a18 GC_generic_malloc (C:/Program Files/Unity/Editor/Data/il2cpp/external/bdwgc/extra/..\malloc.c:264)
    7 libil2cpp.so 0x00000077da497dd4 GC_malloc_kind_global (C:/Program Files/Unity/Editor/Data/il2cpp/external/bdwgc/extra/..\malloc.c:327)
    8 libil2cpp.so 0x00000077da451424 il2cpp::vm::Array::NewSpecific(Il2CppClass*, unsigned long)
    9 libil2cpp.so 0x00000077da930c14 WriteOnlyBufferedStream__ctor_mC8C5F1A5286E8AAE843C0CE0DF984F6102010F98 (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\BestHTTP__46.cpp:8456)
    10 libil2cpp.so 0x00000077da9711c8 HTTP2Handler_RunHandler_mBC0D8349016F5B9B6612A894123ECD4582EE1E96 (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\BestHTTP__49.cpp:18803)
    11 libil2cpp.so 0x000000000233b890 (unknown) (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\BestHTTP__48.cpp:118)
    12 libil2cpp.so 0x00000077da953894 HTTPConnection_ThreadFunc_mE79EAE3CE7AEE073E71DCC2506B7BF6F34996340 (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\BestHTTP__48.cpp:4856)
    13 libil2cpp.so 0x0000000003b93dc0 ContextCallback_Invoke_m872CCCD40428B88C2612772491BE5157895B5F61_inline (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\mscorlib__8.cpp:31373)
    14 libil2cpp.so 0x00000077dc1abdc4 ExecutionContext_RunInternal_mC37E85D6FC972DF219A00FE1EE34329D1D63CC94 (C:/workspace/workspace/p/Library/Bee/artifacts/Android/il2cppOutput/cpp\mscorlib__8.cpp:25089)
    15 libil2cpp.so 0x00000077da430480 il2cpp::vm::Runtime::InvokeWithThrow(MethodInfo const*, void*, void**)
    16 libil2cpp.so 0x00000077da4303cc il2cpp::vm::Runtime::Invoke(MethodInfo const*, void*, void**, Il2CppException**)
    17 libil2cpp.so 0x00000077da4746bc ThreadStart (C:/Program Files/Unity/Editor/Data/il2cpp/libil2cpp/icalls/mscorlib/System.Threading\Thread.cpp:62)
    18 libil2cpp.so 0x00000077da4044cc il2cpp::eek:s::Thread::RunWrapper(void*)
    19 libil2cpp.so 0x00000077da47530c il2cpp::eek:s::ThreadImpl::ThreadStartWrapper(void*)
    20 libc.so 0x000000792bbc7298 <symbols missing for uuid: 1bcad8bca80d38bceb9089f70d394e33>
    21 libc.so 0x000000792bb60bdc <symbols missing for uuid: 1bcad8bca80d38bceb9089f70d394e33>
     
  47. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @d_sharov Unfortunately, i don't have any (good) news.

    "Will switching to a pure Unity Web Request help with this issue?"
    My guess is that, because UnityWebRequest uses native solutions that do its threading/work outside of the c# runtime, it doesn't affected by these or these bugs.


    @JoshPeterson Can i get some help here? These crashes are seem to be like the ones in the Il2cpp crash at malloc, but the first stack trace is in Class:Init.
    As can be read above, the used Unity version is 2022.3.5f1. I receive more and more reports about these kind of crashes, but i don't have any meaningful information to make a bugreport

    However, I did a bug report(IN-51557) last week with a complete repro project that has a very high success rate replicating that specific issue.
    In this case however, it's not a crash (at least neither on my device nor on the reporting client's devices crash). I'm not sure they are related, but when i get the stack traces, threads are in the GC_suspend_handler.
     
  48. d_sharov

    d_sharov

    Joined:
    Dec 24, 2021
    Posts:
    23
    @BestHTTP
    We have moved texture bytes fetch requests to pure Unit Web Requests.
    They work a little slower, but we have completely eliminated such crashes.
    IOS is also getting crashes, but less often.
    Current crash-free stats after transition according to firebase data:
    Android: 70% => 98%
    IOS: 90% => 100%

    We also caught crashes on a request that received a large amount of text.
    When it was called during initialization, where there was a heavy load, then a crash was reproduced with a large one.
    We moved the request to a less busy location and that fixed the issue.

    And as I wrote above - the problem is exclusively on aab.
    In apk, crashes are not reproduced
     
  49. LexaMV

    LexaMV

    Joined:
    Feb 20, 2018
    Posts:
    28
    Need help

    Code (CSharp):
    1. IEnumerator UploadFileData()
    2.     {
    3.         var bytes = File.ReadAllBytes(Application.dataPath + "/1.fbx");
    4.  
    5.         WWWForm form = new WWWForm();
    6.         form.AddBinaryData("file", bytes, "*.fbx", "application/fbx");
    7.  
    8.         using (UnityWebRequest request = UnityWebRequest.Post("http://91.346.196.222:8080/api/v1/resources?type=Fbx", form))
    9.         {
    10.             request.SetRequestHeader("Authorization", "Bearer " + _authToken.token);
    11.  
    12.             yield return request.SendWebRequest();
    13.  
    14.             if (request.isNetworkError || request.isHttpError)
    15.             {
    16.                 Debug.Log(request.error);
    17.             }
    18.             else
    19.             {
    20.                 Debug.Log("Form upload complete! " + request.downloadHandler.text);
    21.  
    22.             }
    23.         }
    24.     }
    how translate this code to Best HTTP?

    I am using
    request.UploadStream = new FileStream(Application.dataPath + "/1.fbx", FileMode.Open); not work correctly
     
  50. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @LexaMV

    It's doesn't work that way because it would send it as-is, without any modification and it seems the server expects it encoded in a form. You could write something like this:

    Code (CSharp):
    1. var request = new HTTPRequest(new Uri("http://91.346.196.222:8080/api/v1/resources?type=Fbx"));
    2. request.AddHeader("Authorization", "Bearer " + _authToken.token);
    3.  
    4. var form = new MultipartFormDataStream(request);
    5. form.AddStreamField(new FileStream(Application.dataPath + "/1.fbx", FileMode.Open), "file", "*.fbx", "application/fbx");
    6.  
    7. request.UploadStream = form;
    8.  
    9. yield return request.Send();