{"action":"closed","issue":{"url":"https://api.github.com/repos/systemd/systemd/issues/8329","repository_url":"https://api.github.com/repos/systemd/systemd","labels_url":"https://api.github.com/repos/systemd/systemd/issues/8329/labels{/name}","comments_url":"https://api.github.com/repos/systemd/systemd/issues/8329/comments","events_url":"https://api.github.com/repos/systemd/systemd/issues/8329/events","html_url":"https://github.com/systemd/systemd/issues/8329","id":301651006,"number":8329,"title":"Race condition between udev rules and hwdb","user":{"login":"whot","id":1487352,"avatar_url":"https://avatars2.githubusercontent.com/u/1487352?v=4","gravatar_id":"","url":"https://api.github.com/users/whot","html_url":"https://github.com/whot","followers_url":"https://api.github.com/users/whot/followers","following_url":"https://api.github.com/users/whot/following{/other_user}","gists_url":"https://api.github.com/users/whot/gists{/gist_id}","starred_url":"https://api.github.com/users/whot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/whot/subscriptions","organizations_url":"https://api.github.com/users/whot/orgs","repos_url":"https://api.github.com/users/whot/repos","events_url":"https://api.github.com/users/whot/events{/privacy}","received_events_url":"https://api.github.com/users/whot/received_events","type":"User","site_admin":false},"labels":[{"id":219549617,"url":"https://api.github.com/repos/systemd/systemd/labels/udev","name":"udev","color":"f7c6c7","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-03-02T04:38:00Z","updated_at":"2018-03-21T05:30:14Z","closed_at":"2018-03-21T05:30:14Z","author_association":"CONTRIBUTOR","body":"### Submission type\r\n\r\n - Bug report\r\n\r\n### systemd version the issue has been seen with\r\n\r\nsystemd-234\r\n\r\n### Used distribution\r\n\r\nFedora 27\r\n\r\n### In case of bug report: Expected behaviour you didn't see\r\n\r\nudev properties applied in lexical order\r\n\r\n### In case of bug report: Unexpected behaviour you saw\r\n\r\nudev properties for a device *sometimes* get overwritten by the hwdb value of a rule with a lower lexical ordering. In other words: 90-something.hwdb+rules overwrites 99-myrule.rules, that shouldn't happen (or at least not randomly).\r\n\r\n### In case of bug report: Steps to reproduce the problem\r\n\r\nThis is a race condition, but it can be reproduced by running the libinput-test-suite-runner. It will fail randomly, some days every time, other times only once out of 10 runs.\r\n\r\n### Full description\r\n\r\n*Note: This was posted to https://lists.freedesktop.org/archives/systemd-devel/2018-February/040332.html but didn't get any traction.*\r\n\r\nI think there is some race conditions between the udev rules and the hwdb and I cannot rely that udev rules are applied consistently on a device.\r\n\r\nFor reference, after building libinput run\r\n```sudo ./build/libinput-test-suite-runner --filter-test=lid_update_hw_on_key_multiple_keyboards```\r\nrun it repeatedly and at some point it will fail.\r\n\r\nThe source of the issue is the udev properties for the test device *sometimes* get overwritten by the hwdb value of a rule with a lower lexical ordering. In other words: 90-something.hwdb+rules overwrites 99-myrule.rules, that shouldn't happen (or at least not randomly).\r\n\r\nFor more detail, the relevant parts are:\r\n\r\n`90-foo.hwdb` entry with a dmi match that assigns a property\r\n\r\n```\r\n    libinput:name:*Lid Switch*:dmi:*:ct9:*\r\n     LIBINPUT_ATTR_LID_SWITCH_RELIABILITY=reliable\r\n```\r\n\r\nand the matching `90-foo.rules`:\r\n```\r\n    KERNELS==\"input*\", \\\r\n      IMPORT{builtin}=\"hwdb 'libinput:name:$attr{name}:$attr{[dmi/id]modalias}'\"\r\n```\r\n\r\nThis assigns 'reliable' to the device.\r\n\r\nI also have per-device udev rules, `92-foo.rules`, in this case:\r\n\r\n```\r\n    ATTRS{name}==\"litest Lid Switch Surface3*\", \\\r\n        ENV{ID_INPUT_SWITCH}=\"1\", \\\r\n        ENV{LIBINPUT_ATTR_LID_SWITCH_RELIABILITY}=\"write_open\"\r\n```\r\n\r\nThis overwrites 'reliable' with 'write_open'.\r\n\r\nOn test-runner start, we install all the udev rules and hwdb files, run hwdb --update and then start the tests.\r\n\r\nIn *most* cases, 'write_open' is correctly assigned to the device. In the failure cases, 'reliable' is assigned. Nothing changes in the udevadm test output and I've verified that the order appears to change, in the failure cases the 92-foo.rules applies before the hwdb overwrites it:\r\n\r\n```\r\n    ATTRS{name}==\"litest Lid Switch Surface3*\",\r\n        ENV{ID_INPUT_SWITCH}=\"1\",\r\n        ENV{BONGO}=\"litest\",\r\n        ENV{LIBINPUT_ATTR_LID_SWITCH_RELIABILITY}=\"write_open\"\r\n\r\n    ATTRS{name}==\"litest Lid Switch Surface3*\",\r\n        ENV{FIRSTVAL}=\"$env{LIBINPUT_ATTR_LID_SWITCH_RELIABILITY}\"\r\n```\r\n\r\nRunning with this udev rule shows that FIRSTVAL is write_open but the real property is 'reliable'.\r\n\r\nThis happens anywhere between 1 out of 3 and 1 out of 50, though it seems to be more common when creating/removing uinput devices like crazy.\r\n\r\n"}}
{"actor":{"display_login":"whot"}}