{"action":"created","issue":{"url":"https://api.github.com/repos/ethereum/go-ethereum/issues/1898","labels_url":"https://api.github.com/repos/ethereum/go-ethereum/issues/1898/labels{/name}","comments_url":"https://api.github.com/repos/ethereum/go-ethereum/issues/1898/comments","events_url":"https://api.github.com/repos/ethereum/go-ethereum/issues/1898/events","html_url":"https://github.com/ethereum/go-ethereum/pull/1898","id":110962986,"number":1898,"title":"core, eth, event, miner, xeth: fix event post / subscription race","user":{"login":"karalabe","id":129561,"avatar_url":"https://avatars.githubusercontent.com/u/129561?v=3","gravatar_id":"","url":"https://api.github.com/users/karalabe","html_url":"https://github.com/karalabe","followers_url":"https://api.github.com/users/karalabe/followers","following_url":"https://api.github.com/users/karalabe/following{/other_user}","gists_url":"https://api.github.com/users/karalabe/gists{/gist_id}","starred_url":"https://api.github.com/users/karalabe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/karalabe/subscriptions","organizations_url":"https://api.github.com/users/karalabe/orgs","repos_url":"https://api.github.com/users/karalabe/repos","events_url":"https://api.github.com/users/karalabe/events{/privacy}","received_events_url":"https://api.github.com/users/karalabe/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ethereum/go-ethereum/labels/review","name":"review","color":"fad8c7"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":13,"created_at":"2015-10-12T12:20:09Z","updated_at":"2015-10-15T15:44:34Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/ethereum/go-ethereum/pulls/1898","html_url":"https://github.com/ethereum/go-ethereum/pull/1898","diff_url":"https://github.com/ethereum/go-ethereum/pull/1898.diff","patch_url":"https://github.com/ethereum/go-ethereum/pull/1898.patch"},"body":"This PR addresses a subtle logical data race, where an event posted into the eventmux may race with incoming subscriptions. Specifically, as the event mux currently delivers events sequentially, it may happen that a post is waiting in the queue and in the mean time a new subscription arrives. The new subscription should not receive the old event, otherwise there may be weird anomalies.\r\n\r\nThe solution is to tag each subscription and each event with a timestamp, and simply compare these before accepting an event for delivery within a subscription. Although it would have been nice to have this timestamp completely hidden, eth filtering is done at a second event mux layer, so we need to surface the event timestamps too to ensure proper filtering there too.\r\n\r\nAnother slight fix opposed to the previous event handling code is that during shutdown, the event mux closed all subscriptions. However, most of the event listeners didn't check if the channel was closed, and just kept spinning wildly reading nil events from the channel. This is probably nothing too big of an issue, but it could cause anomalies, so I've also tried to address these.\r\n\r\n@frozeman Please run this PR in the wallet code, and I would also like to ask you to run your suite of web3 tests to make sure that I haven't accidentally killed some events."},"comment":{"url":"https://api.github.com/repos/ethereum/go-ethereum/issues/comments/148428287","html_url":"https://github.com/ethereum/go-ethereum/pull/1898#issuecomment-148428287","issue_url":"https://api.github.com/repos/ethereum/go-ethereum/issues/1898","id":148428287,"user":{"login":"karalabe","id":129561,"avatar_url":"https://avatars.githubusercontent.com/u/129561?v=3","gravatar_id":"","url":"https://api.github.com/users/karalabe","html_url":"https://github.com/karalabe","followers_url":"https://api.github.com/users/karalabe/followers","following_url":"https://api.github.com/users/karalabe/following{/other_user}","gists_url":"https://api.github.com/users/karalabe/gists{/gist_id}","starred_url":"https://api.github.com/users/karalabe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/karalabe/subscriptions","organizations_url":"https://api.github.com/users/karalabe/orgs","repos_url":"https://api.github.com/users/karalabe/repos","events_url":"https://api.github.com/users/karalabe/events{/privacy}","received_events_url":"https://api.github.com/users/karalabe/received_events","type":"User","site_admin":false},"created_at":"2015-10-15T15:44:34Z","updated_at":"2015-10-15T15:44:34Z","body":"I'm guessing a possible reason would be that a dapp stalling the eth subscription should not stall the rest of the system's event bus. Though it probably still will do so as the lower event mux will block until the upper propagates."}}