Skip to content

fix(lcm): Add retry with refresh token during upload file#2084

Merged
hung-nguyen-hoang merged 1 commit into
masterfrom
GRIF-877
Jul 8, 2026
Merged

fix(lcm): Add retry with refresh token during upload file#2084
hung-nguyen-hoang merged 1 commit into
masterfrom
GRIF-877

Conversation

@hung-nguyen-hoang

@hung-nguyen-hoang hung-nguyen-hoang commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

JIRA: GRIF-877

Summary by CodeRabbit

  • Bug Fixes

    • Improved file upload retry behavior so uploads recover correctly after authentication refreshes and use a fresh file handle on retry.
    • Fixed an issue that could affect retried uploads during authorization failures.
  • Tests

    • Enabled a previously skipped test covering download and decompression of deployed process artifacts.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The do_stream_file method in the connection module was refactored so that the RestClient request, including file handle opening, is constructed inside the retry block, ensuring a fresh file and token on retry. Separately, a previously skipped test for downloading deployed processes was enabled.

Changes

Streaming Upload and Test Enablement

Layer / File(s) Summary
Rebuild request inside retry block
lib/gooddata/rest/connection.rb
Request construction and file opening moved inside Connection.retryable, so retries after token refresh use a freshly opened file and updated auth token instead of reusing the original handle.
Re-enable deployed process download spec
spec/project/full_process_schedule_spec.rb
Changed xit to it, activating the download/decompression assertions for the deployed process test.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant Connection
  participant RestClientRequest

  Caller->>Connection: do_stream_file
  Connection->>Connection: retryable block
  Connection->>RestClientRequest: build request (File.new, x_gdc_authtt)
  RestClientRequest-->>Connection: 401 error
  Connection->>Connection: refresh token
  Connection->>RestClientRequest: rebuild request (fresh File.new, updated x_gdc_authtt)
  RestClientRequest-->>Connection: success
  Connection-->>Caller: result
Loading

Poem

A rabbit hops, file in paw,
Retries the upload, no stale flaw,
Fresh handle open, token anew,
A skipped test wakes, and passes too! 🐇
Hop hop, ship it — the burrow's true.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: upload retries now refresh the token and reopen the file during retry.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
lib/gooddata/rest/connection.rb (1)

530-545: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

File handle leaks on retry.

The fix correctly moves request construction inside the retry block so each retry gets a fresh file handle and refreshed x_gdc_authtt. However, when a retry attempt fails, the File.new(filename, 'rb') from that attempt is never explicitly closed — RestClient does not auto-close File payloads. Each failed attempt leaks one file descriptor, which could exhaust the FD limit under sustained retry loops.

Using File.open with a block around request.execute ensures the handle is closed on both success and failure, while still creating a fresh handle per retry.

♻️ Proposed refactor to ensure file handle cleanup
         b = proc do
-          request = RestClient::Request.new(:method => :put,
-                                            :url => uri.to_s,
-                                            :verify_ssl => verify_ssl,
-                                            :headers => `@webdav_headers.merge`(:x_gdc_authtt => headers[:x_gdc_authtt]),
-                                            :payload => File.new(filename, 'rb'))
-          request.execute
+          File.open(filename, 'rb') do |file|
+            request = RestClient::Request.new(:method => :put,
+                                              :url => uri.to_s,
+                                              :verify_ssl => verify_ssl,
+                                              :headers => `@webdav_headers.merge`(:x_gdc_authtt => headers[:x_gdc_authtt]),
+                                              :payload => file)
+            request.execute
+          end
         end
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/gooddata/rest/connection.rb` around lines 530 - 545, The retryable upload
path still leaks file descriptors because each call to the upload proc creates a
new File handle that is never explicitly closed if RestClient fails. Update the
upload logic inside GoodData::Rest::Connection.retryable and the b proc so the
payload file is opened in a block around request.execute, ensuring every retry
gets a fresh handle and that it is closed on both success and failure while
preserving the refreshed x_gdc_authtt behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@lib/gooddata/rest/connection.rb`:
- Around line 530-545: The retryable upload path still leaks file descriptors
because each call to the upload proc creates a new File handle that is never
explicitly closed if RestClient fails. Update the upload logic inside
GoodData::Rest::Connection.retryable and the b proc so the payload file is
opened in a block around request.execute, ensuring every retry gets a fresh
handle and that it is closed on both success and failure while preserving the
refreshed x_gdc_authtt behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3e1b6470-544e-460f-a788-e1d5c84ab9a1

📥 Commits

Reviewing files that changed from the base of the PR and between a237a35 and 3ff0258.

📒 Files selected for processing (2)
  • lib/gooddata/rest/connection.rb
  • spec/project/full_process_schedule_spec.rb

@zhabba zhabba left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐇

@hung-nguyen-hoang hung-nguyen-hoang added this pull request to the merge queue Jul 8, 2026
Merged via the queue into master with commit f0dd25a Jul 8, 2026
27 of 28 checks passed
@hung-nguyen-hoang hung-nguyen-hoang deleted the GRIF-877 branch July 8, 2026 08:07
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 this pull request may close these issues.

2 participants