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

[bug] Resource response randomly lose some characters in Android dev #6415

Closed
meowtec opened this issue Mar 8, 2023 · 5 comments
Closed
Labels
platform: Android status: needs triage This issue needs to triage, applied to new issues type: bug

Comments

@meowtec
Copy link
Contributor

meowtec commented Mar 8, 2023

Describe the bug

JS resource response randomly lose some characters.

03-10 12:02:38.404 13924 13924 E Tauri/Console: File: https://tauri.localhost/node_modules/.vite/deps/react-dom_client.js?v=0cc140e4 - Line 14117 - Msg: Uncaught SyntaxError: Unexpected identifier

屏幕截图 2023-03-10 200553

屏幕截图 2023-03-08 231606

Code of this line should be hostParentIsContainer = prevHostParentIsContainer; but I got hostParentIsContainer prevHostParentIsContainer;

And every time I reload the page, the location of losing character changed.

Reproduction

tauri-mobile-bug.zip (updated at Fri, 10 Mar 2023 12:00:37 GMT)

NOTE that the page may need reload once or more times. (E.g. using chrome://inspect/#devices to reload it)

Expected behavior

No response

Platform and versions

Environment
  › OS: Windows 10.0.22624 X64
  › Webview2: 110.0.1587.63
  › MSVC:
      - Visual Studio Community 2022
  › Node.js: 16.19.1
  › npm: 8.19.3
  › pnpm: 7.29.0
  › yarn: 1.22.19
  › rustup: 1.25.2
  › rustc: 1.67.1
  › cargo: 1.67.1
  › Rust toolchain: stable-x86_64-pc-windows-msvc

Packages
  › @tauri-apps/cli [NPM]: 2.0.0-alpha.2
thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: Error("unexpected character 't' while parsing major version number")', src\info.rs:566:67
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Stack trace

No response

Additional context

Using Android simulator Pixel_XL_API_33 (x86_64)

It work well if redirect from tauri.localhost to the real host:

屏幕截图 2023-03-10 201045

@meowtec meowtec added status: needs triage This issue needs to triage, applied to new issues type: bug labels Mar 8, 2023
@amrbashir
Copy link
Member

did you use create-tauri-app to bootstrap the project? seems like your vite.conf.json doesn't have necessary setup for mobile

@meowtec
Copy link
Contributor Author

meowtec commented Mar 10, 2023

@amrbashir I didn't follow the document.

Now the WebSocket works but the characters missing still happen.

@meowtec meowtec changed the title [bug] Android dev with vite not working [bug] JS resource response randomly lose some characters in Android dev Mar 10, 2023
@meowtec meowtec changed the title [bug] JS resource response randomly lose some characters in Android dev [bug] Resource response randomly lose some characters in Android dev Mar 10, 2023
@meowtec
Copy link
Contributor Author

meowtec commented Mar 12, 2023

It seems like a bug of attohttpc. After I replaced attohttpc to reqwest this error disappeared.

@meowtec
Copy link
Contributor Author

meowtec commented Mar 12, 2023

It seems because attohttpc use io::copy to obtain the response body, which is not suitable.

I made a simple demo:

use std::net::{TcpStream, SocketAddr};
use std::io::{Write,self};

let mut stream = TcpStream::connect(SocketAddr::from(([192, 168, 74, 1], 1420))).unwrap();
write!(&stream, "GET /node_modules/.vite/deps/react-dom_client.js?v=b8bea35d HTTP/1.1\r\n").unwrap();
write!(&stream, "Host: 192.168.74.1:1420\r\n").unwrap();
write!(&stream, "Connection: close\r\n").unwrap();
write!(&stream, "\r\n").unwrap();

// SAVE HTTP response (including 
let mut body = Vec::new();
io::copy(&mut stream, &mut body).unwrap();

The result may be like this:
1678610254947-bytes.txt

Some bytes will randomly lose.

While if I modify io::copy(...) like this, I will get the correct HTTP response:

// io::copy(&mut stream, &mut body).unwrap();
loop {
    let mut chunk = [0u8; 8192];
    match stream.read(&mut chunk) {
        Ok(size) => {
            if size == 0 {
                break;
            }
            body.extend_from_slice(&chunk[0..size]);
        }
        Err(err) => {
            // TODO
        }
    }
}

lucasfernog added a commit that referenced this issue Mar 17, 2023
* refactor(core): remove attohttpc client, closes #6415

* lint [skip ci]
@sbstp
Copy link

sbstp commented Aug 13, 2023

Hey, attohttpc author here. Sorry you encountered so many issues. I think using reqwest is definitely the right call, reqwest/hyper is way more mature.

Still, I'm going to try to investigate this bug with io::copy, it's really strange...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: Android status: needs triage This issue needs to triage, applied to new issues type: bug
Projects
None yet
Development

No branches or pull requests

5 participants