Does RepositoryPushEvent get fired twice for all pushes?

I have a listener that shoots out messages to slack upon events. Normally just PR events but I recently added a listener for RepositoryPushEvent. I seem to be getting double messages for all pushes. Is that event being fired twice (4.10.1)? Is there a way to acknowledge that I’ve processed an event already?

Definitly running through that code twice

2017-03-29 16:27:08,363 ERROR [AtlassianEvent::thread-3] jshapiro PrSlackListener Push event fired by com.atlassian.stash.internal.hook.PushPostReceiveHook
2017-03-29 16:27:08,738 ERROR [AtlassianEvent::thread-1] jshapiro PrSlackListener Push event fired by com.atlassian.stash.internal.hook.PushPostReceiveHook

Are the refChanges the same for both events?

yes, same ref changes.

Justin,

Have you gotten to the bottom of this yet? Most likely your listener is being registered twice; the system does not raise the event twice.

Are you able to share any code? Are you injecting the EventPublisher and manually registering your listener? In Bitbucket Server it’s generally unnecessary to do that, and doing so can end up registering your listener twice. Simply annotating your method as @EventListener is generally sufficient to get it registered, depending on how your plugin was constructed.

Best regards,
Bryan Turner
Atlassian Bitbucket

I didn’t fix it. I just added some checking to prevent double posting messages. I’m not registering it myself. I only use the annotation. It’s in a class with several other annotated listeners. I have several listener plugins. This is the only place I listen for that event. It is the only listener where this occurs.

Justin,

Can you reach out to me directly via e-mail? Some additional details would help me troubleshoot your issue better. We have other places that listen for RepositoryPushEvent in the base product, and they’re only notified once. There has to be something else going on. Perhaps you can share more in a private conversation. Once we’ve resolved the duplication we can share the solution here for anyone else who’s interested.

Best regards,
Bryan Turner
Atlassian Bitbucket

Justin and Bryan,

I am wondering if you found the solution. I have exactly the same problem with all events and would prefer not to check if it was previously handled.

Thank you in advance.

Sure, I had both 20_stash_callback and 20_bitbucket_callback in my repositories. The upgrade was supposed to clean it up, I’m sure it did but I had modified things and put them back.

So, you basically kept checking if the event was already handled when fired the second time? I am wondering if there’s a solution register event listener only once either through annotations or in atlassian-plugin.xml.

As soon as I replied to your post, I solved the problem myself.

@dennisv - that’s a different solution than what Justin required but I’m glad your problem got solved!

I’ll add a bit more detail to Justin’s reply for anyone else coming across the same problem.

Bitbucket Server adds some server-side hook scripts to the repository directories we keep on the server. These scripts call back into Bitbucket on certain events (before and after git processes a push, for example) so that we can trigger the corresponding events in Java. One of the scripts was called 20_stash_callback but we renamed it to 20_bitbucket_callback. As I understand, Justin put a version of 20_stash_callback back in the repository directory which included both his modifications and the code to call back into Bitbucket. As a result, both his 20_stash_callback script and our own 20_bitbucket_callback script called into Bitbucket and we double-triggered events in Java.

Hopefully, you can understand why we’d prefer people don’t edit the hook scripts. If you need to, please get in touch so we can consider your needs in future versions of Bitbucket Server.

look ma, I’m a cautionary tale!

No, he didn’t keep checking. He removed the (unexpected) 20_stash_callback scripts that were resulting in post-receive hooks being triggered twice for each push, and after that the event was only raised once, by 20_bitbucket_callback.

@dennisv,

I’ve responded to your Stack Overflow post. The solution you describe seems incorrect/incomplete. If you’d like to reach out to me directly, or via Community or Stack Overflow, I’d be happy to help you chase the real issue a little further.

Bryan