New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Strange behavior with webhooks #827
Comments
For the record, removing the from CommitRepoAction (gogs/models/action.go) fixes my problem. |
I've investigated a little bit more, and I think I've found what is going wrong in here. Tell me if I missed something: When you push through ssh,
This process will look at task to update and will then start a new go routine for handling the hooks. this is the go DeliverHooks() call. But it doesn't wait for this go routine to stop (this is because it doesn't want to block for all the hooks). An easy test to show that, is to add a sleep at the beginning of the DeliverHook some logs, and you'll see that those logs will never be shown. This is probably why with one hook I get an error, but with more then one, the find is a little bit longer, and it doesn't even get into the delivery loop. One other possible issue/race condition I've found, is that if DeliverHooks can be called both from the gogs serv and from gogs web, there is nothing that prevents it from calling twice the hooks with the same information. Indeed the only protection, is the find("is_delivered"=false) but if both makes this call at the same time then they could be doing the same thing |
Hi @scritch007 , thanks your report and sorry for late!
I think this right solution, if you can confirm this DID solves your problem, I would remove and push to GitHub. 😄 |
Hi @unknwon Yes this actually fixed the webhooks. Now the "cron" does it for you and correctly :). So this means that in the worst case you'll have to wait 60 seconds (by default) before being notified of the push. I don't think this is a problem, but maybe it would be nice to have a better fix. Maybe for a later version, gogs serv could send a message (http or a signal) to the main gogs web process, so that this triggers the webhooks delivery. It's true that it would be nice to have realtime webhooks, but there are many more important feature then this. |
Right, I forgot that Maybe create a separate issue called |
Yes an enhancement issue would be great. I'm gonna create one, so that you can close this one. |
Avoid identical making calls to GetUserByID(..) in SignedInUser(..)
I update my issue description, regarding the other comments, but I'll leave my initial issue description below.
DeliverHooks called from gogs update doesn't seems to work.
Two issues, first one is the one described in comment 2. The gogs update doesn't wait for the DeliverHooks go routine which means that it is only done partially
Second issue I've found when calling DeliverHooks, not in a go routine, is that for some unknown reason (I'll investigate more on this) the req.Response() when calling the hooks will always fail in this process, but will succeed when called from gogs web
Two errors I've had so far:
[xorm] [debug] 2015/01/03 23:09:09.861022 [time] INSERT INTO
hook_task(
uuid,
type,
url,
payload_content,
content_type,
event_type,
is_ssl,
is_delivered,
is_succeed) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) - args [add0f66e-ff25-4bd3-9412-201af69f085d 1 http://127.0.0.1:3001/hooks/toto/1 {"secret":"DFGHJK","ref":"refs/heads/master","commits":[{"id":"5000a717cf8e8bd1bc1aa503d8e8665f4ec4e74d","message":"FGHJ\n","url":"http://localhost:3000/scritch007/a/commit/5000a717cf8e8bd1bc1aa503d8e8665f4ec4e74d","author":{"name":"Benjamin Legrand","email":"dev@legrand.ws","username":"scritch007"}}],"repository":{"id":2,"name":"a","url":"http://localhost:3000/scritch007/a","description":"","website":"","watchers":0,"owner":{"name":"scritch007","email":"dev@legrand.ws","username":"scritch007"},"private":false},"pusher":{"name":"scritch007","email":"dev@legrand.ws","username":"scritch007"},"before":"749c84d375b86bc1dcc384983b5f3322ec44e5c1","after":"5000a717cf8e8bd1bc1aa503d8e8665f4ec4e74d","compare_url":"http://localhost:3000/scritch007/a/compare/749c84d375b86bc1dcc384983b5f3322ec44e5c1...5000a717cf8e8bd1bc1aa503d8e8665f4ec4e74d"} 1 false false false] - execution took: 63660294ns [xorm] [info] 2015/01/03 23:09:09.861157 [sql] DELETE FROM
update_taskWHERE
uuid= ? [args] [631e6e2e-1033-4af4-81b2-6c7531db70b2] [xorm] [info] 2015/01/03 23:09:09.861346 [sql] SELECT
id,
uuid,
type,
url,
payload_content,
content_type,
event_type,
is_ssl,
is_delivered,
is_succeedFROM
hook_taskWHERE is_delivered=? [args] [[false]] [xorm] [info] 2015/01/03 23:09:09.862708 [sql] UPDATE
hook_taskSET
uuid= ?,
type= ?,
url= ?,
payload_content= ?,
content_type= ?,
event_type= ?,
is_ssl= ?,
is_delivered= ?,
is_succeed= ? WHERE
id= ? [args] [add0f66e-ff25-4bd3-9412-201af69f085d 1 http://127.0.0.1:3001/hooks/toto/1 {"secret":"DFGHJK","ref":"refs/heads/master","commits":[{"id":"5000a717cf8e8bd1bc1aa503d8e8665f4ec4e74d","message":"FGHJ\n","url":"http://localhost:3000/scritch007/a/commit/5000a717cf8e8bd1bc1aa503d8e8665f4ec4e74d","author":{"name":"Benjamin Legrand","email":"dev@legrand.ws","username":"scritch007"}}],"repository":{"id":2,"name":"a","url":"http://localhost:3000/scritch007/a","description":"","website":"","watchers":0,"owner":{"name":"scritch007","email":"dev@legrand.ws","username":"scritch007"},"private":false},"pusher":{"name":"scritch007","email":"dev@legrand.ws","username":"scritch007"},"before":"749c84d375b86bc1dcc384983b5f3322ec44e5c1","after":"5000a717cf8e8bd1bc1aa503d8e8665f4ec4e74d","compare_url":"http://localhost:3000/scritch007/a/compare/749c84d375b86bc1dcc384983b5f3322ec44e5c1...5000a717cf8e8bd1bc1aa503d8e8665f4ec4e74d"} 1 false true false 47]
The text was updated successfully, but these errors were encountered: