{"action":"created","issue":{"url":"https://api.github.com/repos/mautic/mautic/issues/1737","repository_url":"https://api.github.com/repos/mautic/mautic","labels_url":"https://api.github.com/repos/mautic/mautic/issues/1737/labels{/name}","comments_url":"https://api.github.com/repos/mautic/mautic/issues/1737/comments","events_url":"https://api.github.com/repos/mautic/mautic/issues/1737/events","html_url":"https://github.com/mautic/mautic/issues/1737","id":154531620,"number":1737,"title":"Leads receive multiple mails during large campaign","user":{"login":"wittwerch","id":1575445,"avatar_url":"https://avatars.githubusercontent.com/u/1575445?v=3","gravatar_id":"","url":"https://api.github.com/users/wittwerch","html_url":"https://github.com/wittwerch","followers_url":"https://api.github.com/users/wittwerch/followers","following_url":"https://api.github.com/users/wittwerch/following{/other_user}","gists_url":"https://api.github.com/users/wittwerch/gists{/gist_id}","starred_url":"https://api.github.com/users/wittwerch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wittwerch/subscriptions","organizations_url":"https://api.github.com/users/wittwerch/orgs","repos_url":"https://api.github.com/users/wittwerch/repos","events_url":"https://api.github.com/users/wittwerch/events{/privacy}","received_events_url":"https://api.github.com/users/wittwerch/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-05-12T16:56:12Z","updated_at":"2016-05-12T17:00:14Z","closed_at":null,"body":"## Description\r\nWe encountered the problem, that during a large campaign some recipients received the same email more than once (up to 6 times!). Today we could locate the root cause: There were more than one process triggering the campaign running at the same time. The locking done in script_executions.json should ensure, that only one process is running at the same time. Unfortunately that mechanism is not working well for large dataset were sending a campaign can take up to 1.5 hour.\r\nBy default Mautic threats a command (like triggering a campaign) to be \"dead\" after a timeout of 1800s (30min). This means it will simply assume that the process is not running anymore and allow a new command to be launched.\r\n\r\napp/bundles/CoreBundle/Command/ModeratedCommand.php\r\n```\r\n$timeout   = $this->getContainer()->hasParameter('mautic.command_timeout') ?\r\n  $this->getContainer()->getParameter('mautic.command_timeout') : 1800;\r\n..\r\nif ($check + $timeout <= time()) {\r\n  $this->executionTimes['in_progress'][$command][$key] = time();\r\n} else {\r\n```\r\n\r\nIn our case this leads to the situation, that approximately 3-4 process were running in parallel.\r\n\r\n## Steps to reproduce\r\n\r\n1. Create a mail campaign with 500 leads\r\n1. Trigger the campaign (mautic:campaign:trigger)\r\n1. Simulate a long running job by editing the script_executions.json. Just subtract 1800 from the unix timestamp.\r\n1. Trigger the campaign again (mautic:campaign:trigger)\r\n\r\nIn our test around 720 mails were sent in that campaign => leads received the same email twice.\r\n\r\n## Possible solution\r\nI think we should get ride of the command_timeout and instead write the pid of the php process into the script_executions.json file (using a lock, see #1664). This would allow commands to run as long as they take. And still make sure, that the commands start again if the process died. You simply check if a process is there with the pid from the script_executions.json, otherwise the process died and you can start over. That would follow the same mechanism init-script are using on linux distributions.\r\n\r\nIf you agree with that change I would start to implement that improvement."},"comment":{"url":"https://api.github.com/repos/mautic/mautic/issues/comments/218820165","html_url":"https://github.com/mautic/mautic/issues/1737#issuecomment-218820165","issue_url":"https://api.github.com/repos/mautic/mautic/issues/1737","id":218820165,"user":{"login":"jkuchar","id":133822,"avatar_url":"https://avatars.githubusercontent.com/u/133822?v=3","gravatar_id":"","url":"https://api.github.com/users/jkuchar","html_url":"https://github.com/jkuchar","followers_url":"https://api.github.com/users/jkuchar/followers","following_url":"https://api.github.com/users/jkuchar/following{/other_user}","gists_url":"https://api.github.com/users/jkuchar/gists{/gist_id}","starred_url":"https://api.github.com/users/jkuchar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jkuchar/subscriptions","organizations_url":"https://api.github.com/users/jkuchar/orgs","repos_url":"https://api.github.com/users/jkuchar/repos","events_url":"https://api.github.com/users/jkuchar/events{/privacy}","received_events_url":"https://api.github.com/users/jkuchar/received_events","type":"User","site_admin":false},"created_at":"2016-05-12T17:00:14Z","updated_at":"2016-05-12T17:00:14Z","body":"This makes sense for me.\r\n\r\nHowever I'm not sure how this will work without `exec` enabled. (e.g. shared hosting) Any ideas?"}}