{"action":"created","issue":{"url":"https://api.github.com/repos/ev3dev/ev3dev/issues/690","repository_url":"https://api.github.com/repos/ev3dev/ev3dev","labels_url":"https://api.github.com/repos/ev3dev/ev3dev/issues/690/labels{/name}","comments_url":"https://api.github.com/repos/ev3dev/ev3dev/issues/690/comments","events_url":"https://api.github.com/repos/ev3dev/ev3dev/issues/690/events","html_url":"https://github.com/ev3dev/ev3dev/issues/690","id":162403163,"number":690,"title":"Possible race condition when resyncing UART sensor","user":{"login":"bmegli","id":9095769,"avatar_url":"https://avatars.githubusercontent.com/u/9095769?v=3","gravatar_id":"","url":"https://api.github.com/users/bmegli","html_url":"https://github.com/bmegli","followers_url":"https://api.github.com/users/bmegli/followers","following_url":"https://api.github.com/users/bmegli/following{/other_user}","gists_url":"https://api.github.com/users/bmegli/gists{/gist_id}","starred_url":"https://api.github.com/users/bmegli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bmegli/subscriptions","organizations_url":"https://api.github.com/users/bmegli/orgs","repos_url":"https://api.github.com/users/bmegli/repos","events_url":"https://api.github.com/users/bmegli/events{/privacy}","received_events_url":"https://api.github.com/users/bmegli/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ev3dev/ev3dev/labels/sensors","name":"sensors","color":"0052cc"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2016-06-27T08:55:28Z","updated_at":"2016-07-01T23:07:27Z","closed_at":null,"body":"### System information:\r\n\r\nProblem reproducible as reported by @kortschak in https://github.com/ev3dev/ev3dev/issues/679, which was:\r\n>\r\n* I am using: LEGO MINDSTORMS EV3 and FATCATLAB EVB\r\n* I installed ev3dev using this image file: ev3-ev3dev-jessie-2015-12-30.img\r\n* My kernel version is: 4.4.13-12-ev3dev-ev3 also the release 12 on the EVB.\r\n* My host computer is running: Linux\r\n* I am connecting using: Wi-Fi\r\n\r\n### About my issue:\r\n\r\n#### What led up to the situation?\r\n\r\nWhen analysing the code  for issue https://github.com/ev3dev/ev3dev/issues/679 possible race condition between user space sysfs attribute read and resyncing sensor resetting `mode_info` and waiting for new `mode_info` was identified.\r\n\r\nAs a result of race, user trying to read sensor valueX may end up with ENXIO error code (No such device or address).\r\n\r\nThe problem is non-fatal and happens when communication with sensor is failing, error message is reported to the user but it is misleading (\"No such device or address\").\r\n\r\nReproducible as @kortschak reported in https://github.com/ev3dev/ev3dev/issues/679:\r\n\r\n>#### What exactly did you do (or not do) that was effective (or ineffective)?\r\nPlug in FATCATLAB 9DOF to EV3 (or EVB - though slightly different outcome there due presumably to difference in cpu performance between the two).\r\nThen navigate to device browser and click watch values.\r\n\r\n>#### What was the outcome of this action?\r\nThe following notification by brickman for the EV3 \"Error reading from file: No such device or address\" and the following dmesg output:\r\n\r\nSee https://github.com/ev3dev/ev3dev/issues/679#issuecomment-228623924 for output details\r\n\r\n>Pressing back and re-clicking watch values restores the expected brickman behaviour for the EV3, presumably because the device has stabilised after the overruns.\r\n\r\n> Similar behaviours are seen on EVB (see #662 (comment)).\r\n\r\n>#### What outcome did you expect instead?\r\nNormal sensor operation and no kernel noise.\r\n\r\n#### Explanation for race condition\r\n\r\nI originally explained it in https://github.com/ev3dev/ev3dev/issues/679#issuecomment-228623130\r\n\r\nHere's just a brief overview:\r\n- uart sesnor syncs, gets mode info, ACK, sends ACK\r\n- lego_sensor device is registered creating sysfs attributes\r\n- if communication with device fails (e.g. `bad_message_size`) resyncing is started\r\n- during resyncing `mode_info` is reset to default values\r\n- during period after resetting `mode_info` and before getting new `mode_info` from UART sensor we have a race condition with userspace sysfs `valueX` attribute read\r\n\r\nIf valueX is read from sysfs during critical period mode_info `num_values` and `data_sets` are both 0 and `value_show` function in line:\r\nhttps://github.com/ev3dev/lego-linux-drivers/blob/036f41ab854c3cdc21da3b6451a94fa57d2d606a/sensors/lego_sensor_class.c#L421\r\n```\r\n if (index < 0 || index >= lego_sensor_get_num_values(mode_info))\r\n        return -ENXIO;\r\n```\r\nreturns -ENXIO"},"comment":{"url":"https://api.github.com/repos/ev3dev/ev3dev/issues/comments/230065542","html_url":"https://github.com/ev3dev/ev3dev/issues/690#issuecomment-230065542","issue_url":"https://api.github.com/repos/ev3dev/ev3dev/issues/690","id":230065542,"user":{"login":"dlech","id":963645,"avatar_url":"https://avatars.githubusercontent.com/u/963645?v=3","gravatar_id":"","url":"https://api.github.com/users/dlech","html_url":"https://github.com/dlech","followers_url":"https://api.github.com/users/dlech/followers","following_url":"https://api.github.com/users/dlech/following{/other_user}","gists_url":"https://api.github.com/users/dlech/gists{/gist_id}","starred_url":"https://api.github.com/users/dlech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dlech/subscriptions","organizations_url":"https://api.github.com/users/dlech/orgs","repos_url":"https://api.github.com/users/dlech/repos","events_url":"https://api.github.com/users/dlech/events{/privacy}","received_events_url":"https://api.github.com/users/dlech/received_events","type":"User","site_admin":false},"created_at":"2016-07-01T23:07:27Z","updated_at":"2016-07-01T23:07:27Z","body":"So how do you know how many bytes to skip? Did we receive one extra bad byte? Did we receive 1/2 of a message? Did we receive a full length message, but with corrupted data? This is why we need to compare what the driver is receiving vs. what is actually being transmitted from the sensor."}}
{"actor":{"display_login":"dlech"}}