Skip to content

fix(login): put slow operations in go routines to speed up login#7349

Open
jrainville wants to merge 1 commit intodevelopfrom
fix/slow-login-on-bad-connection
Open

fix(login): put slow operations in go routines to speed up login#7349
jrainville wants to merge 1 commit intodevelopfrom
fix/slow-login-on-bad-connection

Conversation

@jrainville
Copy link
Copy Markdown
Member

Needed for status-im/status-app#19856

During my investigation, I found that these two services take a long time to initiate and block the login process. Putting these calls in go routines fixes the issue

status-app PR: status-im/status-app#20144
See the link above for videos

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 2, 2026

⚠️ Companion PR Needs Update

#20144 is not using the latest status-go commit (adf8859d7c59999b179e3ec861141d41b8072eda).

Update vendor/status-go in the companion PR.

@status-im-auto
Copy link
Copy Markdown
Member

status-im-auto commented Mar 2, 2026

Jenkins Builds

Click to see older builds (71)
Commit #️⃣ Finished (UTC) Duration Platform Result
✖️ cce0d28 1 2026-03-02 22:10:20 ~2 min tests 📄log
✔️ cce0d28 1 2026-03-02 22:11:45 ~4 min linux/status-go 📦zip
✖️ cce0d28 1 2026-03-02 22:12:11 ~4 min tests 📄log
✔️ cce0d28 1 2026-03-02 22:12:30 ~4 min macos/status-go 📦zip
✔️ cce0d28 1 2026-03-02 22:15:23 ~7 min linux/nwaku 📦zip
cce0d28 1 2026-03-02 22:16:26 ~8 min macos/nwaku 📄log
✔️ cce0d28 1 2026-03-02 22:20:35 ~12 min tests-rpc 📄log
✔️ cce0d28 1 2026-03-02 22:21:24 ~13 min tests-rpc 📄log
✔️ cce0d28 1 2026-03-02 22:25:42 ~17 min windows/nwaku 📦zip
✔️ c8e5b36 2 2026-03-11 16:38:37 ~6 min linux/status-go 📦zip
✖️ c8e5b36 2 2026-03-11 16:38:47 ~6 min tests 📄log
✔️ c8e5b36 2 2026-03-11 16:40:56 ~8 min macos/status-go 📦zip
✔️ c8e5b36 2 2026-03-11 16:41:12 ~8 min windows/status-go 📦zip
✖️ c8e5b36 2 2026-03-11 16:42:54 ~10 min tests 📄log
✔️ c8e5b36 2 2026-03-11 16:43:02 ~10 min linux/nwaku 📦zip
✔️ c8e5b36 2 2026-03-11 16:46:18 ~14 min macos/nwaku 📦zip
✔️ c8e5b36 2 2026-03-11 16:51:04 ~18 min tests-rpc 📄log
✔️ c8e5b36 2 2026-03-11 16:52:10 ~19 min tests-rpc 📄log
✔️ c8e5b36 2 2026-03-11 16:55:19 ~22 min windows/nwaku 📦zip
✔️ 86dd634 3 2026-03-17 17:02:58 ~5 min macos/status-go 📦zip
✔️ 86dd634 3 2026-03-17 17:06:02 ~8 min windows/status-go 📦zip
✔️ 86dd634 3 2026-03-17 17:12:21 ~14 min macos/nwaku 📦zip
✔️ 86dd634 3 2026-03-17 17:14:22 ~16 min windows/nwaku 📦zip
✔️ 86dd634 3 2026-03-17 17:42:17 ~44 min linux/status-go 📦zip
✖️ 86dd634 3 2026-03-17 17:46:00 ~48 min tests 📄log
✖️ 86dd634 3 2026-03-17 17:50:38 ~52 min tests 📄log
✔️ 86dd634 3 2026-03-17 17:52:19 ~54 min linux/nwaku 📦zip
✖️ 86dd634 3 2026-03-17 18:05:23 ~1 hr 7 min tests-rpc 📄log
✖️ 86dd634 3 2026-03-17 18:05:44 ~1 hr 7 min tests-rpc 📄log
✔️ 40009e7 4 2026-03-18 14:04:30 ~5 min windows/status-go 📦zip
✔️ 40009e7 4 2026-03-18 14:09:54 ~11 min macos/status-go 📦zip
✔️ 40009e7 4 2026-03-18 14:12:20 ~13 min windows/nwaku 📦zip
✔️ 40009e7 4 2026-03-18 14:18:58 ~20 min linux/status-go 📦zip
✔️ 40009e7 4 2026-03-18 14:21:17 ~22 min macos/nwaku 📦zip
✖️ 40009e7 4 2026-03-18 14:21:29 ~22 min tests 📄log
✔️ 40009e7 4 2026-03-18 14:25:09 ~26 min linux/nwaku 📦zip
✖️ 40009e7 4 2026-03-18 14:25:21 ~26 min tests 📄log
✔️ 40009e7 4 2026-03-18 14:34:24 ~35 min tests-rpc 📄log
✔️ 40009e7 4 2026-03-18 14:36:03 ~37 min tests-rpc 📄log
✖️ 40009e7 5 2026-03-18 17:33:39 ~9 min tests 📄log
✖️ 40009e7 6 2026-03-18 19:47:51 ~11 min tests 📄log
✖️ b4cb3a4 5 2026-03-18 20:23:33 ~2 min tests 📄log
✔️ b4cb3a4 5 2026-03-18 20:24:58 ~4 min linux/status-go 📦zip
✔️ b4cb3a4 5 2026-03-18 20:26:40 ~5 min macos/status-go 📦zip
✔️ b4cb3a4 5 2026-03-18 20:26:44 ~5 min windows/status-go 📦zip
✔️ b4cb3a4 5 2026-03-18 20:29:16 ~8 min macos/nwaku 📦zip
✔️ b4cb3a4 5 2026-03-18 20:29:43 ~8 min linux/nwaku 📦zip
✔️ b4cb3a4 5 2026-03-18 20:36:30 ~15 min windows/nwaku 📦zip
✔️ b4cb3a4 5 2026-03-18 20:39:28 ~18 min tests-rpc 📄log
✔️ b4cb3a4 5 2026-03-18 20:39:55 ~18 min tests-rpc 📄log
✔️ b4cb3a4 7 2026-03-18 20:59:13 ~38 min tests 📄log
✔️ f67d3f6 6 2026-03-19 15:27:44 ~4 min macos/status-go 📦zip
✔️ f67d3f6 6 2026-03-19 15:32:02 ~8 min windows/status-go 📦zip
✔️ f67d3f6 6 2026-03-19 15:33:24 ~10 min macos/nwaku 📦zip
✔️ f67d3f6 6 2026-03-19 15:35:40 ~12 min windows/nwaku 📦zip
✖️ f67d3f6 6 2026-03-19 15:39:10 ~16 min tests 📄log
✔️ f67d3f6 6 2026-03-19 15:40:11 ~17 min linux/status-go 📦zip
✔️ f67d3f6 6 2026-03-19 15:46:41 ~23 min linux/nwaku 📦zip
✔️ f67d3f6 6 2026-03-19 15:53:22 ~30 min tests-rpc 📄log
✔️ f67d3f6 6 2026-03-19 15:53:28 ~30 min tests-rpc 📄log
✔️ f67d3f6 8 2026-03-19 16:14:08 ~51 min tests 📄log
✖️ 0531470 7 2026-03-19 17:56:16 ~2 min tests 📄log
✔️ 0531470 7 2026-03-19 17:57:27 ~4 min linux/status-go 📦zip
✔️ 0531470 7 2026-03-19 17:58:18 ~4 min macos/status-go 📦zip
✔️ 0531470 7 2026-03-19 17:59:27 ~5 min windows/status-go 📦zip
✔️ 0531470 7 2026-03-19 18:02:06 ~8 min linux/nwaku 📦zip
✔️ 0531470 7 2026-03-19 18:02:25 ~8 min macos/nwaku 📦zip
✔️ 0531470 7 2026-03-19 18:09:08 ~15 min tests-rpc 📄log
✔️ 0531470 7 2026-03-19 18:09:18 ~15 min tests-rpc 📄log
✔️ 0531470 7 2026-03-19 18:12:29 ~18 min windows/nwaku 📦zip
✔️ 0531470 9 2026-03-19 18:29:51 ~36 min tests 📄log
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ adf8859 8 2026-03-20 15:11:35 ~4 min macos/status-go 📦zip
✔️ adf8859 8 2026-03-20 15:14:46 ~8 min linux/status-go 📦zip
✔️ adf8859 8 2026-03-20 15:14:52 ~8 min windows/status-go 📦zip
✔️ adf8859 8 2026-03-20 15:15:59 ~9 min macos/nwaku 📦zip
✖️ adf8859 8 2026-03-20 15:17:09 ~10 min tests 📄log
✖️ adf8859 10 2026-03-20 15:19:03 ~12 min tests 📄log
✔️ adf8859 8 2026-03-20 15:20:08 ~13 min linux/nwaku 📦zip
✔️ adf8859 8 2026-03-20 15:23:30 ~16 min windows/nwaku 📦zip
✔️ adf8859 8 2026-03-20 15:29:06 ~22 min tests-rpc 📄log
✔️ adf8859 8 2026-03-20 15:29:55 ~23 min tests-rpc 📄log

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 2, 2026

Codecov Report

❌ Patch coverage is 76.19048% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 39.38%. Comparing base (87e5b83) to head (adf8859).

Files with missing lines Patch % Lines
internal/timesource/ntp.go 50.00% 4 Missing and 1 partial ⚠️

❗ There is a different number of reports uploaded between BASE (87e5b83) and HEAD (adf8859). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (87e5b83) HEAD (adf8859)
unit 1 0
Additional details and impacted files
@@             Coverage Diff              @@
##           develop    #7349       +/-   ##
============================================
- Coverage    61.02%   39.38%   -21.64%     
============================================
  Files          824      812       -12     
  Lines       116026   113849     -2177     
============================================
- Hits         70805    44840    -25965     
- Misses       37977    63279    +25302     
+ Partials      7244     5730     -1514     
Flag Coverage Δ
functional 39.38% <76.19%> (+0.25%) ⬆️
unit ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
services/wallet/currency/service.go 59.09% <100.00%> (+0.95%) ⬆️
internal/timesource/ntp.go 60.58% <50.00%> (-31.77%) ⬇️

... and 502 files with indirect coverage changes

@jrainville jrainville force-pushed the fix/slow-login-on-bad-connection branch 2 times, most recently from c8e5b36 to 86dd634 Compare March 17, 2026 16:57
@jrainville
Copy link
Copy Markdown
Member Author

@saledjenic can you review please

@jrainville jrainville force-pushed the fix/slow-login-on-bad-connection branch 4 times, most recently from f67d3f6 to 0531470 Compare March 19, 2026 17:53
}

s.runPeriodically(ctx, s.updateOffset, err == nil)
go func() {
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.

@jrainville this is not the code that I am familiar with, actually I see it for the first time now, but just by checking what runPeriodically does I see at least one issue here and it is that the first check in that function:

	if s.started {
		return
	}

since you added s.runPeriodically to Go routine, it means that line 265 s.started = true is always executed before line 262 and runPeriodically never executes because of the first check there.

So we need to do changes more carefully here, also, I see that this computes a time offset from NTP servers, which is crucial for accepting/rejecting messages, which means this is very important and not sure that the right time will be fetched and used if we delay calls in Go routine. But also would be good to ask @osmaczko and @igor-sirotin for review also, since they were touching this code.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Very good find. I moved the started flag. I'll check with Patryk to see if it's an issue.

I did a quick test and the offset at first is 0s and then 0.5 seconds later it was updated to -2.429584ms, which is very small. I wonder if it could cause issues with some computers though

if err == nil {
_ = s.db.UpdateCachedFormats(fiatFormats)
}
go func() {
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.

In this Go routine no race conditions as I see, but it would be good to add the same proper exit check as we have in the Go routine below:

select {
    case <-ctx.Done():
        return
    default:
}

And another problem could be, but we should check that (maybe only new Status profiles are affected, but maybe not cause the login process takes some time), since UpdateCachedFormats populates the db, which is empty for new profiles, that the client may read empty currency formats before the table gets populated.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In this Go routine no race conditions as I see, but it would be good to add the same proper exit check as we have in the Go routine below

Since this new one doesn't have a ticker, it doesn't need a Done. It's only needed when it's a repeating routine.

since UpdateCachedFormats populates the db, which is empty for new profiles, that the client may read empty currency formats before the table gets populated.

I'll test it. I'll put a sleep in the routine to fake a slow load and then check if I have currencies.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I just tested and it seems ok

Needed for status-im/status-app#19856

During my investigation, I found that these two services take a long time to initiate and block the login process.
Putting these calls in go routines fixes the issue
@jrainville jrainville force-pushed the fix/slow-login-on-bad-connection branch from 0531470 to adf8859 Compare March 20, 2026 15:06
@jrainville jrainville requested a review from osmaczko March 20, 2026 19:40
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.

3 participants