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

[Linux] Hang on app close with started Worker after audio usage stop #3625

Open
itlancer opened this issue Dec 24, 2024 · 0 comments
Open

[Linux] Hang on app close with started Worker after audio usage stop #3625

itlancer opened this issue Dec 24, 2024 · 0 comments
Labels

Comments

@itlancer
Copy link

Problem Description

Application hangs on close with started Worker after audio usage stop.
So there is no way to correct close application in such cases.
It happens with Sound and with NetStream too.

Tested with multiple AIR 51 versions, even with latest AIR 51.1.3.2 with multiple different Linux x86_64 devices (physical and VM), different OS versions and different applications. With and without sudo privileges. With and without workarounds mentioned here #3450.
Tested with multiple Ubuntu x86_64 22.04.4 LTS and Ubuntu x86_64 24.04.1 LTS devices with different window managers.
Same issue in all cases.
There is no such issue with other platforms.

Related issues:
#3619
#3505
#3498
#3453
#3452
#3450
#3389
#2523
#1984

Steps to Reproduce

Launch code below with any Linux x86_64 device.
Notice: launch it from terminal/console to detect that process will not be finished.
Audio file playback will be started. Click anywhere on stage - it will cause sound will be stopped and NativeApplication.nativeApplication.exit() called to close application.

Application example with sources and audio sample attached.
linux_sound_close_worker_hang.zip

package {
	import flash.display.Sprite;
	import flash.media.Sound;
	import flash.media.SoundChannel;
	import flash.net.URLRequest;
	import flash.events.MouseEvent;
	import flash.events.Event;
	import flash.desktop.NativeApplication;
	import flash.system.Worker;
	import flash.system.WorkerDomain;
	
	public class LinuxSoundCloseWorkerHang extends Sprite {
		private var soundChannel:SoundChannel;
		private var worker:Worker;
		
		public function LinuxSoundCloseWorkerHang() {
			if (Worker.current.isPrimordial) {
				addEventListener(Event.ADDED_TO_STAGE, init);
			} else {
				trace("worker");
			}
		}
		
		private function init(e:Event):void {
			removeEventListener(Event.ADDED_TO_STAGE, init);
			
			worker = WorkerDomain.current.createWorker(this.loaderInfo.bytes, true);
			worker.start();
			
			var sound:Sound = new Sound(new URLRequest('audio.mp3'));
			soundChannel = sound.play();
			
			stage.addEventListener(MouseEvent.CLICK, click);
		}
		
		private function click(e:MouseEvent):void {
			trace("click");
			soundChannel.stop();//This line cause application hang on exit
			//worker.terminate();//This line doesn't help here
			NativeApplication.nativeApplication.exit();
		}
	}
}

Actual Result:
Audio playback stop, application visually will be "closed" but application process still will not be finished. You can see it in terminal.

Expected Result:
Application will be closed properly.

Known Workarounds

Terminate Worker before application exit and wait for WorkerState.TERMINATED state.

package {
	import flash.display.Sprite;
	import flash.media.Sound;
	import flash.media.SoundChannel;
	import flash.net.URLRequest;
	import flash.events.MouseEvent;
	import flash.events.Event;
	import flash.desktop.NativeApplication;
	import flash.system.Worker;
	import flash.system.WorkerDomain;
	import flash.system.WorkerState;
	
	public class LinuxSoundCloseWorkerHang extends Sprite {
		private var soundChannel:SoundChannel;
		private var worker:Worker;
		
		public function LinuxSoundCloseWorkerHang() {
			if (Worker.current.isPrimordial) {
				addEventListener(Event.ADDED_TO_STAGE, init);
			} else {
				trace("worker");
			}
		}
		
		private function init(e:Event):void {
			removeEventListener(Event.ADDED_TO_STAGE, init);
			
			worker = WorkerDomain.current.createWorker(this.loaderInfo.bytes, true);
			worker.start();
			
			var sound:Sound = new Sound(new URLRequest('audio.mp3'));
			soundChannel = sound.play();
			
			stage.addEventListener(MouseEvent.CLICK, click);
		}
		
		private function workerStateChanged(e:Event):void {
			trace("workerStateChanged", worker.state);
			if (worker.state == WorkerState.TERMINATED){
				NativeApplication.nativeApplication.exit();
			}
		}
	
		private function click(e:MouseEvent):void {
			trace("click");
			soundChannel.stop();
			worker.addEventListener(Event.WORKER_STATE, workerStateChanged);
			worker.terminate();
		}
	}
}
@itlancer itlancer added the Bug label Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant