{"action":"closed","issue":{"url":"https://api.github.com/repos/bft-smart/library/issues/50","repository_url":"https://api.github.com/repos/bft-smart/library","labels_url":"https://api.github.com/repos/bft-smart/library/issues/50/labels{/name}","comments_url":"https://api.github.com/repos/bft-smart/library/issues/50/comments","events_url":"https://api.github.com/repos/bft-smart/library/issues/50/events","html_url":"https://github.com/bft-smart/library/issues/50","id":275087302,"node_id":"MDU6SXNzdWUyNzUwODczMDI=","number":50,"title":"[BUG] Messages to multiple targets","user":{"login":"bergerch","id":5364442,"node_id":"MDQ6VXNlcjUzNjQ0NDI=","avatar_url":"https://avatars3.githubusercontent.com/u/5364442?v=4","gravatar_id":"","url":"https://api.github.com/users/bergerch","html_url":"https://github.com/bergerch","followers_url":"https://api.github.com/users/bergerch/followers","following_url":"https://api.github.com/users/bergerch/following{/other_user}","gists_url":"https://api.github.com/users/bergerch/gists{/gist_id}","starred_url":"https://api.github.com/users/bergerch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bergerch/subscriptions","organizations_url":"https://api.github.com/users/bergerch/orgs","repos_url":"https://api.github.com/users/bergerch/repos","events_url":"https://api.github.com/users/bergerch/events{/privacy}","received_events_url":"https://api.github.com/users/bergerch/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-11-18T15:37:56Z","updated_at":"2018-09-25T19:10:49Z","closed_at":"2018-09-25T19:10:49Z","author_association":"NONE","body":"While building a Forwarder with BFT-SMaRt, I encountered a severe bug that occurs when sending a single message to multiple targets:\r\n\r\nhttps://github.com/bft-smart/library/blob/6892ab38135a222a2cf5d54fbbd5c586ec0aef6f/src/bftsmart/communication/client/netty/NettyClientServerCommunicationSystemServerSide.java#L274:L283\r\n\r\nThe bug is here:\r\n```\r\nfor (int i = 0; i < targets.length; i++) {\r\n\t\t\trl.readLock().lock();\r\n\t\t\t//sendLock.lock();\r\n\t\t\ttry {       \r\n\t\t\t\tNettyClientServerSession ncss = (NettyClientServerSession) sessionTable.get(targets[i]);\r\n\t\t\t\tif (ncss != null) {\r\n\t\t\t\t\tChannel session = ncss.getChannel();\r\n\t\t\t\t\tsm.destination = targets[i];\r\n\t\t\t\t\t//send message\r\nsession.writeAndFlush(sm);\r\n```\r\n**Problem:**\r\nwriteAndFlush() works asynchronously, so you can not assume that the messages have been already sent when the _for loop_ goes to the next iteration. But in the next iteration the _destination_ field of the same object (sm) is being modified and since the objects are passed by reference in Java, the destination field will have the same value (target[1] instead of target[0]) for both iterations, which leads to them being encoded in exactly the same way: with the same MACs being applied to them although they are being sent to different clients. This leads to one client rejecting the message because it thinks that the MAC is corrupt. \r\n\r\n**Solution:**\r\nIt is sufficient to make a shallow copy and pass the copied object to writeAndFlush()"}}
{"actor":{"display_login":"jcs47"}}