Back

[SOLVED] AppwriteException: null, OS Error: Bad file descriptor, errno = 9 (0)

  • 0
  • Flutter
Victor1337
6 Mar, 2023, 08:48

I am seeing AppwriteException: null, OS Error: Bad file descriptor, errno = 9 (0), from time to time, it is hard to reproduce. I add new content to AppWrite DB and if physical iOS device is in a certain state, like locked in the background, I might get this. (Using a FutureBuilder to get here, and spitting this out by going to snapshot.hasError on future resolve)

else if (snapshot.hasError) { // Get.offAll(MainScreen()); print(snapshot.error); return Center(child: Column( children: [ Text('${snapshot.error}'), const Icon(Icons.error_outline), ], ),); }

TL;DR
Sometimes, when a new stream event is fired and the app is in the background, an AppwriteException with the error message "null, OS Error: Bad file descriptor, errno = 9 (0)" occurs. This issue seems to be a known Flutter issue and is related to background operations on mobile devices. The user has temporarily solved the issue by shutting down the stream and only activating it when the AppLifecycleState is resumed. The suggested solution is to be careful when performing background operations on mobile devices.
Drake
7 Mar, 2023, 17:00

Ya, this seems like a known flutter issue: https://github.com/dart-lang/http/issues/197

You have to be very careful about doing stuff in the background on mobile.

Victor1337
7 Mar, 2023, 17:21

Got a bit confusing, tough, not doing anything in the bg

Drake
7 Mar, 2023, 17:30

You said:

physical iOS device is in a certain state, like locked in the background, I might get this

Victor1337
7 Mar, 2023, 18:23

Yes, I really don't do any background operations, There are no life cycle operations, all are on active state. I only have a StreamBuilder watching a collection, and sometimes I get that error, when a new stream event is fired and the app is the background.

Victor1337
7 Mar, 2023, 18:23

The sometimes is really weird, I do 20 times the same thing, and the 21st this can happen.

Victor1337
7 Mar, 2023, 18:24

Going back on doing more testing.

Victor1337
7 Mar, 2023, 18:25

I do have the same data, structure, function on another widget, but coming from firestore, the same StreamBuilder.

Drake
7 Mar, 2023, 18:29

when a new stream event is fired and the app is the background.

When I say background operation, I mean code that is executed while the app is in the background.

Victor1337
8 Mar, 2023, 09:09

Hmm, I now shutdown the stream and only activate it when AppLifecycleState is resumed. Feels hacky, but it works for now.

Drake
8 Mar, 2023, 17:17

[SOLVED] AppwriteException: null, OS Error: Bad file descriptor, errno = 9 (0)

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more