Skip to content
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

Syncing New Pages Can Error with "409 Conflict" #139

Closed
byronmccollum opened this issue Nov 19, 2021 · 4 comments · Fixed by #174
Closed

Syncing New Pages Can Error with "409 Conflict" #139

byronmccollum opened this issue Nov 19, 2021 · 4 comments · Fixed by #174

Comments

@byronmccollum
Copy link

byronmccollum commented Nov 19, 2021

Possibly a race condition when creating new pages. There seems to be two distinct operations, as indicated by the page's history:

  1. Create New Blank Page
  2. Sync Page Contents

We are seeing the following error when creating new pages:

FATAL Confluence API returned unexpected status: 409 Conflict, output: ""

It is believed the above two phases happening in quick succession might be the cause. A resync will allow the second operation to succeed.

@byronmccollum
Copy link
Author

byronmccollum commented Nov 19, 2021

We added some retry logic to our CI, and as you can see in the logs, this might be related to page locking.

> Syncing team/retry-test.md
2021-11-19 18:59:05.137 INFO  processing team/retry-test.md
2021-11-19 18:59:05.578 INFO  page will be stored under path: GCT Home > Team > Retry Test
2021-11-19 18:59:05.999 INFO  the leading H1 heading will be excluded from the Confluence output
2021-11-19 18:59:06.160 FATAL Confluence API returned unexpected status: 409 Conflict, output: ""
Retry 1/5 exited 1, retrying in 1 seconds...
2021-11-19 18:59:07.176 INFO  processing team/retry-test.md
2021-11-19 18:59:07.552 INFO  page will be stored under path: GCT Home > Team > Retry Test
2021-11-19 18:59:07.603 INFO  the leading H1 heading will be excluded from the Confluence output
2021-11-19 18:59:08.009 INFO  edit locked on page "Retry Test" by user "[MASKED]" to prevent manual edits
2021-11-19 18:59:08.131 INFO  page successfully updated: [MASKED]/spaces/GCT/pages/2630353989/Retry+Test
[MASKED]/spaces/GCT/pages/2630353989/Retry+Test

@JAndritsch
Copy link
Contributor

JAndritsch commented Apr 11, 2022

I'm seeing the same thing. I ran mark to create several new pages. The page that threw an exception was created but has no content. Here is the request and error returned by Confluence during the "Update" call for that page:

Request:

2022-04-11 13:38:08.589 TRACE rest: PUT /wiki/rest/api/content/3279323546 HTTP/1.1
Host: somewhere.atlassian.net
Authorization: Basic TOKEN
Content-Type: application/json

{"ancestors":[{"id":"3279323269"}],"body":{"storage":{"representation":"storage","value":"Page Content Here"}},"id":"3279323546","metadata":{"labels":[]},"title":"My Page","type":"page","version":{"minorEdit":true,"number":2}}

Response:

2022-04-11 13:38:08.997 FATAL Confluence API returned unexpected status: 409 Conflict, output: "{"statusCode":409,"data":{"authorized":false,"valid":true,"errors":[],"successful":false},"message":"com.atlassian.confluence.api.service.exceptions.ConflictException: javax.persistence.OptimisticLockException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) : [com.atlassian.confluence.pages.Page#3279323546]"}"

Is there a reason why creating a new page requires a Create followed by an Update? I've never looked at the Confluence API. Can you not provide contents when creating a new page?

Edit: I see why. The page needs to exist in order to handle processing the attachments and that logic happens in either a create or update scenario.

@JAndritsch
Copy link
Contributor

So, adding a time.Sleep(1 * time.Second) after the Create call and before the Update seems to resolve the issue for me. This feels kinda hacky, but if @kovetskiy isn't opposed to it I would be willing to put that in a PR.

JAndritsch added a commit to JAndritsch/mark that referenced this issue Apr 12, 2022
This helps mitigate a 409 conflict response from Confluence when
creating a new page and then updating it right away. This may not be the
cleanest solution, but it seems to do the trick.

Resolves kovetskiy#139
@JAndritsch
Copy link
Contributor

I opened a PR for it either way. I'm happy to explore other options if this doesn't seem like the way to go.

kovetskiy pushed a commit that referenced this issue Apr 22, 2022
This helps mitigate a 409 conflict response from Confluence when
creating a new page and then updating it right away. This may not be the
cleanest solution, but it seems to do the trick.

Resolves #139
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants