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

fix(mobile): ios random logout #8997

Merged
merged 9 commits into from
Apr 23, 2024
Merged

fix(mobile): ios random logout #8997

merged 9 commits into from
Apr 23, 2024

Conversation

alextran1502
Copy link
Contributor

@alextran1502 alextran1502 commented Apr 21, 2024

fix #8146

The issue is in the method _isEndpointAvailable

  Future<bool> _isEndpointAvailable(String serverUrl) async {
    final Client client = Client();

    if (!serverUrl.endsWith('/api')) {
      serverUrl += '/api';
    }

    try {
      final response = await client
          .get(
            Uri.parse(serverUrl),
          )
          .timeout(const Duration(seconds: 5));

+      if (response.statusCode == 502) {
+        _log.severe(
+          "Server Gateway Error: ${response.body} - Cannot communicate to the server",
+        );
+        return false;
+      }
    } on TimeoutException catch (_) {
      return false;
    } on SocketException catch (_) {
      return false;
    }
    return true;
  }

Even when the server is down, the get request can return a response with HTTP status code 502, which should be checked and handled similarly to TimoutException or SocketException to enter the offline mode.

@alextran1502 alextran1502 changed the title fix(mobile): random logout fix(mobile): ios random logout Apr 21, 2024
Copy link

cloudflare-pages bot commented Apr 21, 2024

Deploying immich with  Cloudflare Pages  Cloudflare Pages

Latest commit: a7c0451
Status: ✅  Deploy successful!
Preview URL: https://70f6dd65.immich.pages.dev
Branch Preview URL: https://fix-mobile-random-logout.immich.pages.dev

View logs

@alextran1502 alextran1502 marked this pull request as draft April 21, 2024 18:44
@alextran1502 alextran1502 self-assigned this Apr 23, 2024
Copy link
Contributor

@mmomjian mmomjian left a comment

Choose a reason for hiding this comment

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

LGTM. Hopefully at a minimum the increased logging will help provide info.

Do we know why the 502 is getting hit / server is unreachable? From my external monitoring tools (which checks for both page content and HTTP return code) Immich Web and API endpoints are rock solid.

@alextran1502
Copy link
Contributor Author

Do we know why the 502 is getting hit / server is unreachable? From my external monitoring tools (which checks for both page content and HTTP return code) Immich Web and API endpoints are rock solid.

@mmomjian We don't. My guess is the internal timeout mechanism of the HTTP client. During my testing, I saw it returns 502 sometimes when the server is up and solid during the login process. I submitted the build for TestFlight, and we should be able to test this mechanism on your phones before merging it

@alextran1502 alextran1502 marked this pull request as ready for review April 23, 2024 19:05
.get(
Uri.parse(serverUrl),
)
.timeout(const Duration(seconds: 5));

if (response.statusCode == 502) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You should probably do the opposite actually. If it isn't a 200, log the error and return false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done; it never hit a valid GET endpoint, so it returned 404 or 512. I modify to use GET /server-info/ping to get a valid HTTP 200 when possible

Copy link
Contributor

Choose a reason for hiding this comment

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

Will $serverUrl contain the /api suffix even if not provided on the login screen? I know it works without it currently but im not sure where that gets added/checked.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mmomjian it gets added if it is not included

@alextran1502 alextran1502 merged commit 48b0b7e into main Apr 23, 2024
23 checks passed
@alextran1502 alextran1502 deleted the fix/mobile-random-logout branch April 23, 2024 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Immich iOS keeps logging out after a day or so
3 participants