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

Can not push scrcpy-server, adb: error: failed to read copy response #4638

Open
2 tasks done
18637 opened this issue Feb 1, 2024 · 12 comments
Open
2 tasks done

Can not push scrcpy-server, adb: error: failed to read copy response #4638

18637 opened this issue Feb 1, 2024 · 12 comments

Comments

@18637
Copy link

18637 commented Feb 1, 2024

  • I have read the FAQ.
  • I have searched in existing issues.

Environment

  • OS: Windows
  • scrcpy version: v2.1.1 (The reason for this is I found later versions of SCRCPY automatically turned on the screen when connecting)
  • installation method: Windows release...
  • device model: Samsung A14 5G
  • Android version: 13
  • Connection: Via TCPIP

Describe the bug
Scrcpy works fine for a period of time. Ranging from half a day to several days. I am always connecting and disconnecting constantly. Scrcpy then fails to start. Output from terminal is

adb: error: failed to read copy response
ERROR: "adb push" returned with value 1
ERROR: Server connection failed 

I am unable to connect to the phone again with Scrcpy unless I reboot the computer (I don't need to touch the phone at all).

If I try to manually push "scrcpy-server" I get the same adb: error: failed to read copy response.
I can push any other file to the phone no problems at all??
If I use another computer - no problems at all. The problem lies solely with the pushing of the scrcpy-server after a period of connections and disconnections.
I have Changed sim cards (to rule this out) no difference.

Looking at the adb client code below this seems to be the issue

 if (msg_bytes_left > 0) {
                ssize_t rc = adb_read(fd, buf.end(), msg_bytes_left);
                if (rc <= 0) {
                    Error("failed to read copy failure message");
                    return false;
                }

Full section of code and code location https://android.googlesource.com/platform/system/core/+/d427b54c535d3f56e9db947efa4878346541f890/adb/client/file_sync_client.cpp

bool ReadAcknowledgements(bool read_all = false) {
        // We need to read enough such that adbd's intermediate socket's write buffer can't be
        // full. The default buffer on Linux is 212992 bytes, but there's 576 bytes of bookkeeping
        // overhead per write. The worst case scenario is a continuous string of failures, since
        // each logical packet is divided into two writes. If our packet size if conservatively 512
        // bytes long, this leaves us with space for 128 responses.
        constexpr size_t max_deferred_acks = 128;
        auto& buf = acknowledgement_buffer_;
        adb_pollfd pfd = {.fd = fd.get(), .events = POLLIN};
        while (!deferred_acknowledgements_.empty()) {
            bool should_block = read_all || deferred_acknowledgements_.size() >= max_deferred_acks;
            ssize_t rc = adb_poll(&pfd, 1, should_block ? -1 : 0);
            if (rc == 0) {
                CHECK(!should_block);
                return true;
            }
            if (acknowledgement_buffer_.size() < sizeof(sync_status)) {
                const ssize_t header_bytes_left = sizeof(sync_status) - buf.size();
                ssize_t rc = adb_read(fd, buf.end(), header_bytes_left);
                if (rc <= 0) {
                    Error("failed to read copy response");
                    return false;
                }
                buf.resize(buf.size() + rc);
                if (rc != header_bytes_left) {
                    // Early exit if we run out of data in the socket.
                    return true;
                }
                if (!should_block) {
                    // We don't want to read again yet, because the socket might be empty.
                    continue;
                }
            }
            auto* hdr = reinterpret_cast<sync_status*>(buf.data());
            if (hdr->id == ID_OKAY) {
                buf.resize(0);
                if (hdr->msglen != 0) {
                    Error("received ID_OKAY with msg_len (%" PRIu32 " != 0", hdr->msglen);
                    return false;
                }
                CopyDone();
                continue;
            } else if (hdr->id != ID_FAIL) {
                Error("unexpected response from daemon: id = %#" PRIx32, hdr->id);
                return false;
            } else if (hdr->msglen > SYNC_DATA_MAX) {
                Error("too-long message length from daemon: msglen = %" PRIu32, hdr->msglen);
                return false;
            }
            const ssize_t msg_bytes_left = hdr->msglen + sizeof(sync_status) - buf.size();
            CHECK_GE(msg_bytes_left, 0);
            if (msg_bytes_left > 0) {
                ssize_t rc = adb_read(fd, buf.end(), msg_bytes_left);
                if (rc <= 0) {
                    Error("failed to read copy failure message");
                    return false;
                }
                buf.resize(buf.size() + rc);
                if (rc != msg_bytes_left) {
                    if (should_block) {
                        continue;
                    } else {
                        return true;
                    }
                }
                std::string msg(buf.begin() + sizeof(sync_status), buf.end());
                ReportDeferredCopyFailure(msg);
                buf.resize(0);
                return false;
            }
        }
        return true;
    }

I don't know enough to understand what it means.

Turning off and on the computer to fix the issue is no a valid option for me.

I have tried resetting the NETWORK on the computer and editing the TIMEWAIT for TCP but nothing I have done or can do will fix the problem without a reboot of the computer.

Any ideas or thoughts? There is this issue which is similar #3241 same error at least but connecting via USB cable where I am not and have worked out it's only related to pushing the scrcpy-server.

@rom1v
Copy link
Collaborator

rom1v commented Feb 2, 2024

scrcpy version: v2.1.1 (The reason for this is I found later versions of SCRCPY automatically turned on the screen when connecting)

Even v2.1.1 should do that.

Anyway, there is an option --no-power-on since scrcpy 1.24.

adb: error: failed to read copy response

That's an adb connection issue. Try adb kill-server, or adb disconnect before restarting scrcpy.

@18637
Copy link
Author

18637 commented Feb 2, 2024

Sorry Forgot to include that doing the following

adb kill-server, or adb disconnect or both, then restarting adb and re connecting.

Makes no difference. Still fails to push and I lose no other adb functionality.

I can still run an adb shell, run commands and also push files to the phone so I can't see there is an issue with adb??

The only thing that is failing is pushing the scrcpy-server.

@rom1v
Copy link
Collaborator

rom1v commented Feb 2, 2024

I can still run an adb shell, run commands and also push files to the phone so I can't see there is an issue with adb??

If I try to manually push "scrcpy-server" I get the same adb: error: failed to read copy response.

If you reproduce the problem with adb only (without scrcpy), the issue is necessary with adb.

(to push the file, scrcpy does nothing else than just executing an adb push command)

Turning off and on the computer to fix the issue is no a valid option for me.

Just for testing, what if you reboot the phone instead? What if you use another phone on this computer?

I can push any other file to the phone no problems at all??

Even to the same target (adb push somefile /data/local/tmp/scrcpy-server.jar)?

Try another adb version maybe? (there might be a bug in a specific version)

@18637
Copy link
Author

18637 commented Feb 2, 2024

For starters, I appreciate your help.

I can't reproduce the problem without involving "scrcpy-server". That is the only file that fails to push when it gets in this state.

If I turn the phone off and on, the problem still persists. There is no change. same error.

From the same computer I still push the scrcpy-server to a different phone. But this is not the main phone I use scrcpy for so maybe over time it might do the same but I cant confirm that.

I have tried pushing files fine but i havent tried pushing a file and naming it scrcpy.server.jar as per adb push somefile /data/local/tmp/scrcpy-server.jar

I was thinking it was to do with (I assume not knowing too much) it was some tcp connection issue scrcpy was trying to setup.

If its purely a push issue, is there a way to pre push the scrcpy-server, start scrcpy via a adb command and then when I shut down scrcpy the scrcpy-server remains on the phone as an alternative?

@18637
Copy link
Author

18637 commented Feb 2, 2024

Ok I tested the commands above when it is in a broken state

C:\Users\User\Shadow>adb push devices.txt /data/local/tmp/scrcpy-server.jar
devices.txt: 1 file pushed, 0 skipped. 0.0 MB/s (89 bytes in 0.019s)

C:\Users\User\Shadow>adb push scrcpy-server /data/local/tmp/scrcpy-server.jar
scrcpy-server: 1 file pushed, 0 skipped. 20.1 MB/s (56995 bytes in 0.003s)
adb: error: failed to read copy response

@18637
Copy link
Author

18637 commented Feb 2, 2024

After reboot. I tested new version. Took about 3 hrs to stop working.

C:\Users\User\Shadow_new>scrcpy
scrcpy 2.3.1 <https://github.com/Genymobile/scrcpy>
INFO: ADB device found:
INFO:     --> (tcpip)  192.168.193.202:5555            device  SM_A146P
C:\Users\User\Shadow_new\scrcpy-server: 1 file pushed, 0 skipped. 18.9 MB/s (66007 bytes in 0.003s)
adb: error: failed to read copy response
ERROR: "adb push" returned with value 1
ERROR: Server connection failed

@18637
Copy link
Author

18637 commented Feb 4, 2024

Is there anything else I can try?

@18637
Copy link
Author

18637 commented Feb 10, 2024

@rom1v

I want to be able to prove the fault is only related to adb.

To test this, When this error happens i will push the server to the phone by another computer. Then go back to the one I am having issues with.

I then want to start the pushed server without pushing it because its already there and plus it will fail.

How do I start it manually (so it does not try and push) then if its just a push error I should be able to run scrcpy.

@rom1v
Copy link
Collaborator

rom1v commented Feb 10, 2024

Remove this to avoid pushing the server:

ok = push_server(&server->intr, serial);

And run with --no-cleanup to prevent removing it from the device.

@18637
Copy link
Author

18637 commented Feb 11, 2024

Thank you.

Well I tried for almost the day on Windows and Linux just could not build get scrcpy to build. :-(

I got this far and then could not get any further. I just can't get past this point.

┌──(kali㉿kali)-[~/Downloads/scrcpy]
└─$ sudo ./release.sh                                        
./gradlew clean
Starting a Gradle Daemon, 3 busy and 2 stopped Daemons could not be reused, use --status for details

BUILD SUCCESSFUL in 8s
1 actionable task: 1 executed
rm -rf "dist" "build-test" "build-server" \
        "build-win32" "build-win64"
[ -d "build-test" ] || ( mkdir "build-test" && \
        meson setup "build-test" -Db_sanitize=address )
The Meson build system
Version: 1.2.3
Source dir: /home/kali/Downloads/scrcpy
Build dir: /home/kali/Downloads/scrcpy/build-test
Build type: native build
Project name: scrcpy
Project version: 2.3.1
C compiler for the host machine: cc (gcc 13.2.0 "cc (Debian 13.2.0-5) 13.2.0")
C linker for the host machine: cc ld.bfd 2.41
Host machine cpu family: x86_64
Host machine cpu: x86_64
Found pkg-config: /usr/bin/pkg-config (1.8.1)
Run-time dependency libavformat found: YES 60.16.100
Run-time dependency libavcodec found: YES 60.31.102
Run-time dependency libavutil found: YES 58.29.100
Run-time dependency libswresample found: YES 4.12.100
Run-time dependency sdl2 found: YES 2.30.0
Run-time dependency libavdevice found: YES 60.3.100
Run-time dependency libusb-1.0 found: YES 1.0.26
Checking for function "strdup" : YES 
Checking for function "asprintf" : YES 
Checking for function "vasprintf" : YES 
Checking for function "nrand48" : YES 
Checking for function "jrand48" : YES 
Checking for function "reallocarray" : YES 
Header "sys/socket.h" has symbol "SOCK_CLOEXEC" : YES 
Configuring config.h using configuration
Program ./scripts/build-wrapper.sh found: YES (/home/kali/Downloads/scrcpy/server/./scripts/build-wrapper.sh)
Build targets in project: 14

scrcpy 2.3.1

  User defined options
    b_sanitize: address

Found ninja-1.11.1 at /usr/bin/ninja
ninja -C "build-test"                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
ninja: Entering directory `build-test'
[31/118] Compiling C object app/scrcpy.p/src_server.c.o
../app/src/server.c:120:1: warning: ‘push_server’ defined but not used [-Wunused-function]
  120 | push_server(struct sc_intr *intr, const char *serial) {
      | ^~~~~~~~~~~
[114/118] Generating server/scrcpy-server with a custom command
(not invoking gradle, since we are root)
[118/118] Linking target app/test_vector
./gradlew -p server check

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.4/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

BUILD SUCCESSFUL in 23s
48 actionable tasks: 48 executed
[ -d "build-server" ] || ( mkdir "build-server" && \
        meson setup "build-server" --buildtype release -Dcompile_app=false )
The Meson build system
Version: 1.2.3
Source dir: /home/kali/Downloads/scrcpy
Build dir: /home/kali/Downloads/scrcpy/build-server
Build type: native build
Project name: scrcpy
Project version: 2.3.1
C compiler for the host machine: cc (gcc 13.2.0 "cc (Debian 13.2.0-5) 13.2.0")
C linker for the host machine: cc ld.bfd 2.41
Host machine cpu family: x86_64
Host machine cpu: x86_64
Program ./scripts/build-wrapper.sh found: YES (/home/kali/Downloads/scrcpy/server/./scripts/build-wrapper.sh)
Build targets in project: 2

scrcpy 2.3.1

  User defined options
    buildtype  : release
    compile_app: false

Found ninja-1.11.1 at /usr/bin/ninja
ninja -C "build-server"                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
ninja: Entering directory `build-server'
[0/1] Generating server/scrcpy-server with a custom command
(not invoking gradle, since we are root)
platform-tools-34.0.5 found
SDL2-2.28.5 found
ffmpeg-6.1-scrcpy-3 found
libusb-1.0.26 found
rm -rf "build-win32"
mkdir -p "build-win32/local"
cp -r app/prebuilt-deps/data/ffmpeg-6.1-scrcpy-3/win32/. "build-win32/local/"
cp -r app/prebuilt-deps/data/SDL2-2.28.5/i686-w64-mingw32/. "build-win32/local/"
cp -r app/prebuilt-deps/data/libusb-1.0.26/libusb-MinGW-Win32/. "build-win32/local/"
meson setup "build-win32" \
        --pkg-config-path="build-win32/local/lib/pkgconfig" \
        -Dc_args="-I/home/kali/Downloads/scrcpy/build-win32/local/include" \
        -Dc_link_args="-L/home/kali/Downloads/scrcpy/build-win32/local/lib" \
        --cross-file=cross_win32.txt \
        --buildtype=release --strip -Db_lto=true \
        -Dcompile_server=false \
        -Dportable=true
The Meson build system
Version: 1.2.3
Source dir: /home/kali/Downloads/scrcpy
Build dir: /home/kali/Downloads/scrcpy/build-win32
Build type: cross build
Project name: scrcpy
Project version: 2.3.1
C compiler for the host machine: i686-w64-mingw32-gcc (gcc 12.0.0 "i686-w64-mingw32-gcc (GCC) 12-win32")
C linker for the host machine: i686-w64-mingw32-gcc ld.bfd 2.41
C compiler for the build machine: cc (gcc 13.2.0 "cc (Debian 13.2.0-5) 13.2.0")
C linker for the build machine: cc ld.bfd 2.41
Build machine cpu family: x86_64
Build machine cpu: x86_64
Host machine cpu family: x86
Host machine cpu: i686
Target machine cpu family: x86
Target machine cpu: i686
Windows resource compiler: GNU windres (GNU Binutils) 2.41
Found pkg-config: /usr/bin/i686-w64-mingw32-pkg-config (1.8.1)
Run-time dependency libavformat found: YES 60.16.100
Run-time dependency libavcodec found: YES 60.31.102
Run-time dependency libavutil found: YES 58.29.100
Run-time dependency libswresample found: YES 4.12.100
Run-time dependency sdl2 found: YES 2.28.5
Run-time dependency libusb-1.0 found: YES 1.0.26
Library mingw32 found: YES
Library ws2_32 found: YES
Checking for function "strdup" : YES 
Checking for function "asprintf" : YES 
Checking for function "vasprintf" : YES 
Checking for function "nrand48" : NO 
Checking for function "jrand48" : NO 
Checking for function "reallocarray" : NO 
Configuring config.h using configuration
Build targets in project: 3

scrcpy 2.3.1

  User defined options
    Cross files    : cross_win32.txt
    buildtype      : release
    pkg_config_path: build-win32/local/lib/pkgconfig
    strip          : True
    b_lto          : true
    c_args         : -I/home/kali/Downloads/scrcpy/build-win32/local/include
    c_link_args    : -L/home/kali/Downloads/scrcpy/build-win32/local/lib
    compile_server : false
    portable       : true

Found ninja-1.11.1 at /usr/bin/ninja
ninja -C "build-win32"                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
ninja: Entering directory `build-win32'
[30/63] Compiling C object app/scrcpy.exe.p/src_server.c.obj
../app/src/server.c:120:1: warning: ‘push_server’ defined but not used [-Wunused-function]
  120 | push_server(struct sc_intr *intr, const char *serial) {
      | ^~~~~~~~~~~
[63/63] Linking target app/scrcpy.exe
mkdir -p "dist/scrcpy-win32-v2.3.1-2-g5a6b8310"
cp "build-server"/server/scrcpy-server "dist/scrcpy-win32-v2.3.1-2-g5a6b8310/"
cp: cannot stat 'build-server/server/scrcpy-server': No such file or directory
make: *** [release.mk:105: dist-win32] Error 1                                                    

@rom1v
Copy link
Collaborator

rom1v commented Feb 11, 2024

sudo ./release.sh
…

[114/118] Generating server/scrcpy-server with a custom command
(not invoking gradle, since we are root)

Do not execute as root! (no sudo)

@18637
Copy link
Author

18637 commented Feb 12, 2024

Thank you again. There must have been some some permission issues and It could not create and delete folders. Once I sorted that It ran without root.

I waited until scrcpy was no longer working on this computer and did the following.

Left side original scrcpy | Right modified scrcpy with no push

Scrcpy_issue

Since adb still works in this state and I can push any other file except the scrcpy-server. I am not sure what this proves if anything other than the issue is pushing the file scrcpy-server?

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

No branches or pull requests

2 participants