Skip to content

Invalid Argument error on brscan5 device #132

@Szum123321

Description

@Szum123321

Hi!

I am trying to share my scanner Brother MFC-L2802DN using brscan5 driver over the local network via an arch linux server.
The daemon starts up correctly, but segfaults when a scan is about to start.
What i found is that the second call to sane_open within the same sane_init/sane_exit session leads to an Invalid Argument error.

git commit: 31c3c9e (branch master, rev 321)
build date: 2026-01-03T20:32:45Z
reading access rules from file /etc/airsane/access.conf
start time is 32520.49
reading device options from '/etc/airsane/options.conf'
enumerating  devices...
sane_init(nullptr, nullptr)
sane_get_devices() ...
... sane_get_devices() -> SANE_Status Success
found: brother5:bus1;dev12 (Brother MFC-L2802DN)
stable unique name: brother5:Brother MFC-L2802DN:1
uuid: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
sane_open(brother5:bus1;dev12) -> 0x6785a003b580
[source] := "FlatBed"
[source] := "Automatic Document Feeder(left aligned)"
sane_close(0x6785a003b580)
published as 'Brother MFC-L2802DN'
end time is 32520.68
startup took 0.19 secconds
listening on 127.0.0.1:8090
listening on [::1]:8090
allowing 192.168.0.246, matching rule: local on *
document format requested: image/jpeg
document format used: image/jpeg
job kind: single
using color gamma of 0.56
allowing 192.168.0.246, matching rule: local on *
allowing 192.168.0.246, matching rule: local on *
sane_open(brother5:bus1;dev12) -> SANE_Status Invalid argument

The same thing occurs when testing the setup from a python script.

import sane

sane.init()

dev_handle=sane.get_devices()[0][0]
dev=sane.open(dev_handle)
print(f"First run: {dev.scanner_model}")
dev.close()

dev=sane.open(dev_handle)
print(f"Second run: {dev.scanner_model}")

Produces:

First run: ('Brother', 'MFC-L2802DN')
Traceback (most recent call last):
  File "<python-input-0>", line 10, in <module>
    dev=sane.open(dev_handle)
  File "/usr/lib/python3.13/site-packages/sane.py", line 412, in open
    return SaneDev(devname)
  File "/usr/lib/python3.13/site-packages/sane.py", line 164, in __init__
    d['dev'] = _sane._open(devname)
               ~~~~~~~~~~~^^^^^^^^^
_sane.error: Invalid argument

While the following code works correctly:

import sane

sane.init()

dev_handle=sane.get_devices()[0][0]
dev=sane.open(dev_handle)
print(f"First run: {dev.scanner_model}")
dev.close()
sane.exit()
sane.init()
dev=sane.open(dev_handle)
print(f"Second run: {dev.scanner_model}")

and outputs:

First run: ('Brother', 'MFC-L2802DN')
Second run: ('Brother', 'MFC-L2802DN')

The issue appears to be due to the particular brscan5 scanner driver. So far i tried patching out the reference counting in sanecpp/sanecpp.cpp.
This leads to multiple repeated calls to sane_init and exit, which seems to work fine. I have yet to test the system at any load levels or for a longer span of time than 5 minutes.

I have not fully studied the architecture of this system to be sure that this would patch the behavior, and most certainly, this breaks other vendor's scanners.

I hope to be able to fix this issue permanently, but i understand that breaking other devices is not acceptable. please let me know what are your thought on this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions