sbs20 / scanservjs

SANE scanner nodejs web ui
https://sbs20.github.io/scanservjs/
GNU General Public License v2.0
766 stars 145 forks source link

"/usr/bin/scanimage -A" is working from shell but not node.js #618

Open Oliv4945 opened 1 year ago

Oliv4945 commented 1 year ago

Describe the bug Hello, I am trying to use ScanservJS in a Docker container, alongside with scanbd (scanner button polling process) and sane-epjitsu backend.

Scanservjs is able to detect the scanner but not connect to it, the log is:

scanservjs-webserver-1  | [2023-06-26T09:28:24.189Z] INFO (Process): { execute: '/usr/bin/scanimage -L' }
scanservjs-webserver-1  | [2023-06-26T09:28:32.432Z] INFO (Process): {
scanservjs-webserver-1  |   execute: '/usr/bin/scanimage -d net:localhost:epjitsu:libusb:001:005 -A'
scanservjs-webserver-1  | }
scanservjs-webserver-1  | [2023-06-26T09:28:32.479Z] ERROR (Application): Ignoring net:localhost:epjitsu:libusb:001:005. Error: Error: Command failed: /usr/bin/scanimage -d net:localhost:epjitsu:libusb:001:005 -A
scanservjs-webserver-1  | Output format is not set, using pnm as a default.
scanservjs-webserver-1  | scanimage: open of device net:localhost:epjitsu:libusb:001:005 failed: Error during device I/O
scanservjs-webserver-1  | 

But what is surprising me is that if I manually trigger /usr/bin/scanimage -d net:localhost:epjitsu:libusb:001:005 -A inside the container it works perfectly fine:

# docker compose exec webserver /usr/bin/scanimage -d net:localhost:epjitsu:libusb:001:005 -A
Output format is not set, using pnm as a default.

All options specific to device `net:localhost:epjitsu:libusb:001:005':
  Scan Mode:
    --source ADF Front|ADF Back|ADF Duplex [ADF Front]
        Selects the scan source (such as a document-feeder).
    --mode Lineart|Gray|Color [Lineart]
        Selects the scan mode (e.g., lineart, monochrome, or color).
    --resolution 50..600dpi (in steps of 1) [300]
        Sets the resolution of the scanned image.
  Geometry:
    -t 0..289.353mm (in steps of 0.0211639) [0]
        Top-left y position of scan area.
    --page-width 2.70898..219.428mm (in steps of 0.0211639) [215.872]
        Specifies the width of the media.  Required for automatic centering of
        sheet-fed scans.
    --page-height 0..450.707mm (in steps of 0.0211639) [292.062]
        Specifies the height of the media, 0 will auto-detect.
  Enhancement:
    --brightness -127..127 (in steps of 1) [0]
        Controls the brightness of the acquired image.
    --contrast -127..127 (in steps of 1) [0]
        Controls the contrast of the acquired image.
    --threshold 0..255 (in steps of 1) [120]
        Select minimum-brightness to get a white point
    --threshold-curve 0..127 (in steps of 1) [55]
        Dynamic threshold curve, from light to dark, normally 50-65
  Sensors:
    --scan[=(yes|no)] [no] [hardware]
        Scan button
    --page-loaded[=(yes|no)] [yes] [hardware]
        Page loaded
    --top-edge[=(yes|no)] [no] [hardware]
        Paper is pulled partly into adf
    --cover-open[=(yes|no)] [no] [hardware]
        Cover open
    --power-save[=(yes|no)] [no] [hardware]
        Scanner in power saving mode

To Reproduce Steps to reproduce the behavior:

  1. Setup scanbd, sane on the host
  2. Setup scanservjs docker container
  3. Test scanimage -d net:localhost:epjitsu:libusb:001:005 -A within the container
  4. Open scanservjs webpage
  5. See error

Expected behavior scanimage -A should work when triggered by the Node.js server

Client:

Server:

Thanks for your help

killermouse0 commented 10 months ago

Same issue here. I worked around it by editing /lib/systemd/system/scanbm.socket and changing MaxConnections=1 to MaxConnections=2. You also need to run systemctl daemon-reload after editing.

What tipped me off is that I can see this in /var/log/syslog:

Jan  6 14:23:56 raspberrypi systemd[1]: scanbm.socket: Too many incoming connections (1), dropping connection.

I think that scanservjs tries to run two scanimage commands back-to-back and the second one occurs before the first one closed its socket, but I'm just speculating here. I've tried to pinpoint this in the code, but haven't figured it out yet. I imagine adding a small delay after each scanimage command would fix it.

Hope this helps someone out there :)