-
Notifications
You must be signed in to change notification settings - Fork 333
bug proxy crashes #190
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
bug proxy crashes #190
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -400,7 +400,8 @@ func (s *server) startClient(userID string, textjid string, token string, subscr | |||||
| jid, _ := parseJID(textjid) | ||||||
| deviceStore, err = container.GetDevice(context.Background(), jid) | ||||||
| if err != nil { | ||||||
| panic(err) | ||||||
| log.Error().Err(err).Msg("Failed to get device") | ||||||
| deviceStore = container.NewDevice() | ||||||
| } | ||||||
| } else { | ||||||
| log.Warn().Msg("No jid found. Creating new device") | ||||||
|
|
@@ -437,28 +438,28 @@ func (s *server) startClient(userID string, textjid string, token string, subscr | |||||
| var proxyURL string | ||||||
| err = s.db.Get(&proxyURL, "SELECT proxy_url FROM users WHERE id=$1", userID) | ||||||
| if err == nil && proxyURL != "" { | ||||||
|
|
||||||
| parsed, perr := url.Parse(proxyURL) | ||||||
| if perr != nil { | ||||||
| log.Warn().Err(perr).Str("proxy", proxyURL).Msg("Invalid proxy URL, skipping proxy setup") | ||||||
| } else { | ||||||
|
|
||||||
| log.Info().Str("proxy", proxyURL).Msg("Configuring proxy") | ||||||
|
|
||||||
| if parsed.Scheme == "socks5" || parsed.Scheme == "socks5h" { | ||||||
| // Build SOCKS dialer from URL (supports user:pass in URL) | ||||||
| dialer, derr := proxy.FromURL(parsed, nil) | ||||||
| if derr != nil { | ||||||
| log.Warn().Err(derr).Str("proxy", proxyURL).Msg("Failed to build SOCKS proxy dialer, skipping proxy setup") | ||||||
| } else { | ||||||
| // Apply proxy to both clients now that we know it's valid. | ||||||
| httpClient.SetProxy(proxyURL) | ||||||
| client.SetSOCKSProxy(dialer, whatsmeow.SetProxyOptions{}) | ||||||
| log.Info().Msg("SOCKS proxy configured successfully") | ||||||
| } | ||||||
| } else { | ||||||
| // For http/https, apply to both clients. | ||||||
| httpClient.SetProxy(proxyURL) | ||||||
| client.SetProxyAddress(parsed.String(), whatsmeow.SetProxyOptions{}) | ||||||
| log.Info().Msg("HTTP/HTTPS proxy configured successfully") | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| } | ||||||
| clientManager.SetHTTPClient(userID, httpClient) | ||||||
|
|
||||||
|
|
@@ -555,9 +556,65 @@ func (s *server) startClient(userID string, textjid string, token string, subscr | |||||
| } else { | ||||||
| // Already logged in, just connect | ||||||
| log.Info().Msg("Already logged in, just connect") | ||||||
| err = client.Connect() | ||||||
| if err != nil { | ||||||
| panic(err) | ||||||
|
|
||||||
| // Retry logic com backoff exponencial | ||||||
|
||||||
| // Retry logic com backoff exponencial | |
| // Retry logic with linear backoff |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The values 3 for max retries and 5 * time.Second for the backoff interval are hardcoded. It's a good practice to define these 'magic numbers' as named constants (e.g., maxConnectionRetries and connectionRetryBaseWait) at the top of the function or file. This improves readability and makes the code easier to maintain and configure.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block of code (lines 399-409) appears to be a duplicate of an earlier block (lines 370-380). The
deviceStoreis re-initialized here, but this new value is not used, as thewhatsmeow.Clientwas already created on lines 392/394 with thedeviceStorefrom the first block. This redundant code can be confusing and should be removed to improve maintainability.