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

MainLoop hangs with concurrent Events #10329

Closed
0b1kn00b opened this issue Jul 26, 2021 · 6 comments
Closed

MainLoop hangs with concurrent Events #10329

0b1kn00b opened this issue Jul 26, 2021 · 6 comments
Assignees
Milestone

Comments

@0b1kn00b
Copy link

0b1kn00b commented Jul 26, 2021

haxe build 1d5f076

//stx.stream.Timeout
var a = new Timeout(100).prj();//tink.core.Future
var b = new Timeout(2000).prj();
var c = a.merge(b,(_,_) -> Noise);
    c.handle(
      (_) -> {
        //reaches here and then hangs.
        trace('done');
      }
    );

I think this should work for the unit test. There should be a bunch of logging.

haxelib git stx_stream https://github.com/ohmrun/stx_stream.git
cd $HAXELIB_PATH/stx_stream/git
haxe issue1.hxml

mine looks like:

Issue.hx:16: main
TRACE 2021-07-26 12:00:33 [stx/stream] stx/stream/Timeout.hx:6 timeout#e835: 100
TRACE 2021-07-26 12:00:33 [stx/stream] stx/stream/Timeout.hx:6 timeout#a8fc: 2000
TRACE 2021-07-26 12:00:33 [stx/stream] stx/stream/Timeout.hx:28 timeout#a8fc tick. cancelled: false time 0.000139951705932617188
TRACE 2021-07-26 12:00:33 [stx/stream] stx/stream/Timeout.hx:32 a8fc finished?false
TRACE 2021-07-26 12:00:33 [stx/stream] stx/stream/Timeout.hx:38 a8fc CONTINUE
TRACE 2021-07-26 12:00:33 [stx/stream] stx/stream/Timeout.hx:28 timeout#e835 tick. cancelled: false time 0.00291991233825683594
TRACE 2021-07-26 12:00:33 [stx/stream] stx/stream/Timeout.hx:32 e835 finished?false
TRACE 2021-07-26 12:00:33 [stx/stream] stx/stream/Timeout.hx:38 e835 CONTINUE
TRACE 2021-07-26 12:00:33 [stx/stream] stx/stream/Timeout.hx:28 timeout#e835 tick. cancelled: false time 0.106240034103393555
TRACE 2021-07-26 12:00:33 [stx/stream] stx/stream/Timeout.hx:32 e835 finished?true
TRACE 2021-07-26 12:00:33 [stx/stream] stx/stream/Timeout.hx:34 e835 COMPLETE
TRACE 2021-07-26 12:00:33 [stx/stream] stx/stream/Timeout.hx:28 timeout#a8fc tick. cancelled: false time 0.20699000358581543
TRACE 2021-07-26 12:00:33 [stx/stream] stx/stream/Timeout.hx:32 a8fc finished?false
TRACE 2021-07-26 12:00:33 [stx/stream] stx/stream/Timeout.hx:38 a8fc CONTINUE
TRACE 2021-07-26 12:00:33 [stx/stream] stx/stream/Timeout.hx:28 timeout#a8fc tick. cancelled: false time 0.418076992034912109
TRACE 2021-07-26 12:00:33 [stx/stream] stx/stream/Timeout.hx:32 a8fc finished?false
TRACE 2021-07-26 12:00:33 [stx/stream] stx/stream/Timeout.hx:38 a8fc CONTINUE
TRACE 2021-07-26 12:00:34 [stx/stream] stx/stream/Timeout.hx:28 timeout#a8fc tick. cancelled: false time 0.633017063140869141
TRACE 2021-07-26 12:00:34 [stx/stream] stx/stream/Timeout.hx:32 a8fc finished?false
TRACE 2021-07-26 12:00:34 [stx/stream] stx/stream/Timeout.hx:38 a8fc CONTINUE
TRACE 2021-07-26 12:00:34 [stx/stream] stx/stream/Timeout.hx:28 timeout#a8fc tick. cancelled: false time 0.85195612907409668
TRACE 2021-07-26 12:00:34 [stx/stream] stx/stream/Timeout.hx:32 a8fc finished?false
TRACE 2021-07-26 12:00:34 [stx/stream] stx/stream/Timeout.hx:38 a8fc CONTINUE
TRACE 2021-07-26 12:00:34 [stx/stream] stx/stream/Timeout.hx:28 timeout#a8fc tick. cancelled: false time 1.07482194900512695
TRACE 2021-07-26 12:00:34 [stx/stream] stx/stream/Timeout.hx:32 a8fc finished?false
TRACE 2021-07-26 12:00:34 [stx/stream] stx/stream/Timeout.hx:38 a8fc CONTINUE
TRACE 2021-07-26 12:00:34 [stx/stream] stx/stream/Timeout.hx:28 timeout#a8fc tick. cancelled: false time 1.30210709571838379
TRACE 2021-07-26 12:00:34 [stx/stream] stx/stream/Timeout.hx:32 a8fc finished?false
TRACE 2021-07-26 12:00:34 [stx/stream] stx/stream/Timeout.hx:38 a8fc CONTINUE
TRACE 2021-07-26 12:00:35 [stx/stream] stx/stream/Timeout.hx:28 timeout#a8fc tick. cancelled: false time 1.53316497802734375
TRACE 2021-07-26 12:00:35 [stx/stream] stx/stream/Timeout.hx:32 a8fc finished?false
TRACE 2021-07-26 12:00:35 [stx/stream] stx/stream/Timeout.hx:38 a8fc CONTINUE
TRACE 2021-07-26 12:00:35 [stx/stream] stx/stream/Timeout.hx:28 timeout#a8fc tick. cancelled: false time 1.76773405075073242
TRACE 2021-07-26 12:00:35 [stx/stream] stx/stream/Timeout.hx:32 a8fc finished?false
TRACE 2021-07-26 12:00:35 [stx/stream] stx/stream/Timeout.hx:38 a8fc CONTINUE
TRACE 2021-07-26 12:00:35 [stx/stream] stx/stream/Timeout.hx:28 timeout#a8fc tick. cancelled: false time 2.00864601135253906
TRACE 2021-07-26 12:00:35 [stx/stream] stx/stream/Timeout.hx:32 a8fc finished?true
TRACE 2021-07-26 12:00:35 [stx/stream] stx/stream/Timeout.hx:34 a8fc COMPLETE
Issue.hx:26: done
^CStdlib.Sys.Break

@RealyUniqueName
Copy link
Member

Is it possible to assemble a demo using std types and preferably without 9000 libraries? :)

@0b1kn00b
Copy link
Author

Why, was it too hard to paste those three lines of code into a shell? I'll have a go

@lublak
Copy link
Contributor

lublak commented Jul 26, 2021

Your example is based on libraries. Libraries themselves can have errors and should not be considered in the unit test.
The example should be kept as minimal as possible without dependencies.

@0b1kn00b
Copy link
Author

I figured as this is like my third bug report regarding the MainLoop that I could indulge myself in a sarcastic winge. I'm not sure what the exchange rate is.

@0b1kn00b
Copy link
Author

0b1kn00b commented Jul 27, 2021

using tink.CoreApi;

class Main {
  static function main() {
    trace("init");
    var a = new Timeout(100).prj();
    var b = new Timeout(2000).prj();
    var c = a.merge(b,(_,_) -> Noise);
        c.handle(
          (_) -> {
            trace('done');
          }
        );
    }
}
@:forward abstract Timeout(Future<Noise>){
  public function new(ms:Int){
    final id = Math.round(Math.random() * 1000);
    trace('timeout#$id: $ms');
    final multiplier = 1.02;
    function step(time:Int){
      return Math.round(time * multiplier);
    }
    this = new Future(
      (cb) -> {
        final start      = haxe.Timer.stamp();
        function exit_time(){
          return start + (ms/1000);
        }
        function is_finished(){
          return haxe.Timer.stamp() >= exit_time();
        }
        function since(){
          return haxe.Timer.stamp() - start;
        }
        var cancelled    = false;
        var   next       = 200 > ms ? ms : 200;
        var   event      = null;
              event      = haxe.MainLoop.add(
                () -> {
                  trace('timeout#${id} tick. cancelled: $cancelled time ${since()}');
                  if(cancelled){
                    event.stop();
                  }else{
                    trace('$id finished?${is_finished()}');
                    if(is_finished()){
                      trace('$id COMPLETE');
                      event.stop();
                      cb(Noise);
                    }else{
                      trace('$id CONTINUE');
                      next = step(next);
                      event.delay(next/1000);
                    }
                  }
                }
              );
        return () -> {
          cancelled = true;
        } 
      }
    );
  }
  public function prj():Future<Noise>{
    return this;
  }
}

build.hxml

-cp src
-lib tink_core
-D analyzer-optimize
-main Main
--interp

@RealyUniqueName
Copy link
Member

This is a regression in 4.2 and it affects threaded targets only.
Minimal sample:

import haxe.MainLoop;

class Main {
	static function main() {
		var e1 = null;
		var e2 = null;
		e1 = MainLoop.add(() -> {
			e1.stop();
			trace('e1 stop');
		});
		e2 = MainLoop.add(() -> {
			e2.stop();
			trace('e2 stop');
		});
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants