tools icon indicating copy to clipboard operation
tools copied to clipboard

Investigate race conditions on analytics related files

Open eliasyishak opened this issue 2 years ago • 2 comments

Investigate the potential problems and solutions for the situation where there are multiple dash tools running with this package and are attempting to write to the same log file.

How should we handle this?

Is it okay if some tools have persisted logs that don't get stored locally as a result of simultaneous write operations?

Possibly a lock file, but will this result in some tools hanging on exit as other processes finish writing to logs?

eliasyishak avatar Sep 26 '23 18:09 eliasyishak

Found in flutter tool crash reporting. As we have been onboarding more tools onto package:unified_analytics, we may be running into race conditions caused by repeated read/write operations to the same files by different dart processes.

Found in beta/3.19.0-0.3.pre

FileSystemException: FileSystemException: Cannot open file, path = 'C:\Users\VaibhavWadhwa\AppData\Roaming\.dart-tool\dart-flutter-telemetry-session.json' (OS Error: The requested operation cannot be performed on a file with a user-mapped section open.
, errno = 1224)
at _File.throwIfError(file_impl.dart:675)
at _File.openSync(file_impl.dart:490)
at _File.writeAsBytesSync(file_impl.dart:644)
at _File.writeAsStringSync(file_impl.dart:668)
at ForwardingFile.writeAsStringSync(forwarding_file.dart:150)
at Session.getSessionId(session.dart:59)
at UserProperty._toMap(user_property.dart:63)
at UserProperty.preparePayload(user_property.dart:50)
at generateRequestBody(utils.dart:109)
at AnalyticsImpl.send(analytics.dart:599)
at Doctor.diagnose(doctor.dart:447)
at <asynchronous gap>(async)
at DoctorCommand.runCommand(doctor.dart:49)
at <asynchronous gap>(async)
at FlutterCommand.run.<anonymous closure>(flutter_command.dart:1389)
at <asynchronous gap>(async)
at AppContext.run.<anonymous closure>(context.dart:153)
at <asynchronous gap>(async)
at CommandRunner.runCommand(command_runner.dart:212)
at <asynchronous gap>(async)
at FlutterCommandRunner.runCommand.<anonymous closure>(flutter_command_runner.dart:355)
at <asynchronous gap>(async)
at AppContext.run.<anonymous closure>(context.dart:153)
at <asynchronous gap>(async)
at FlutterCommandRunner.runCommand(flutter_command_runner.dart:295)
at <asynchronous gap>(async)
at run.<anonymous closure>.<anonymous closure>(runner.dart:119)
at <asynchronous gap>(async)
at AppContext.run.<anonymous closure>(context.dart:153)
at <asynchronous gap>(async)
at main(executable.dart:90)
at <asynchronous gap>(async)

eliasyishak avatar Jan 30 '24 18:01 eliasyishak

We should make adjustments to the log handler and session handler so that we are not writing to these files every time we send an event... instead maybe flushing out writes every 10 seconds will reduce the i/o

eliasyishak avatar Feb 08 '24 21:02 eliasyishak