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

🐛 Bug Report: Functions always throw timeout error after creating user account during 1min #6195

Open
2 tasks done
istornz opened this issue Sep 8, 2023 · 2 comments
Open
2 tasks done
Assignees
Labels
bug Something isn't working product / functions Fixes and upgrades for the Appwrite Functions.

Comments

@istornz
Copy link

istornz commented Sep 8, 2023

👟 Reproduction steps

This bug is very strange :/

  1. Create a very simple function which list documents (I only tried with Dart).
  2. Upload the function (manual or VCS Github)
  3. On the mobile app, create a new session with a provider account.createOAuth2Session() (I tried with Apple only)
  4. User is now created & logged
  5. During ~1min, try to call the function, it always throw Execution timed out..

If you do the same steps BUT at step 5. wait ~1min (just do nothing at all, just take a coffee ☕️) & then call the function: it works well 😅.
After waiting this time it always work.

My supposition is when creating a new user, Appwrite has a process in background, we need to wait this process to finish & then we can launch functions.

👍 Expected behavior

During the first ~1min, try to call the function, it should work & not throw error.

👎 Actual Behavior

During the first ~1min, try to call the function, it throw error Execution timed out.

🎲 Appwrite version

Version 1.4.x

💻 Operating system

Linux

🧱 Your Environment

I use Hetzner with 2 vCPU, 4GB Ram, 20Gb disk storage (CX21 offer)

Appwrite version: 1.4.2.

👀 Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

🏢 Have you read the Code of Conduct?

@istornz istornz added the bug Something isn't working label Sep 8, 2023
@eldadfux eldadfux added the product / functions Fixes and upgrades for the Appwrite Functions. label Sep 9, 2023
@istornz
Copy link
Author

istornz commented Sep 11, 2023

I tried to make the issue reproductible to debug it & patch it :slight_smile:

1- So first create a very basic function in Dart:

import 'dart:async';
import 'dart:io';
import 'package:dart_appwrite/dart_appwrite.dart';

Future<dynamic> main(final context) async {
  final client = Client()
      .setEndpoint(Platform.environment['APPWRITE_FUNCTION_ENDPOINT']!)
      .setProject(Platform.environment['APPWRITE_FUNCTION_PROJECT_ID'])
      .setKey(Platform.environment['APPWRITE_API_KEY'])
      .setSelfSigned(status: true);

  final databases = Databases(client);
  try {
    final response = await databases.listDocuments(
      databaseId: 'DB_ID',
      collectionId: 'SYNC_DB',
      queries: [
        Query.limit(100),
      ],
    );
    context.log('Fetched !');
    context.log(response.documents.length.toString());
  } catch (e) {
    // You can also log errors to the console
    context.error('There is an error!');
    context.error(e.toString());
  }

  // `res.json()` is a handy helper for sending JSON
  return context.res.json({
    'motto': 'Build Fast. Scale Big. All in One Place.',
    'learn': 'https://appwrite.io/docs',
    'connect': 'https://appwrite.io/discord',
    'getInspired': 'https://builtwith.appwrite.io',
  });
}

2- Add API key to function which had documents list permissions at minimum
3- Add execute access to Users (important)
4- Login to the app with Provider (Google or Apple, don't tried with others), don't make it with email/password, it can't always crash with (sometimes yes but not always).

_account.createOAuth2Session();

5- Direct after login success, execute the function with a button for example

_functions.createExecution(
      functionId: '64fecda6870bb9d745ed',
      body: jsonEncode(
        {
          'data': true,
        },
      ),
      method: 'POST',
    );

And you will get Error: timed out (it can arrive that the first one completed, so just re-execute the function).

@stnguyen90 stnguyen90 self-assigned this Sep 11, 2023
@stnguyen90
Copy link
Contributor

@istornz, thanks so much for the details! 🙏🏼 I'll try to reproduce this as soon as I can.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working product / functions Fixes and upgrades for the Appwrite Functions.
Projects
None yet
Development

No branches or pull requests

3 participants