Problems with Fiber

Options
vitorcmaia
edited July 2013 in Photon Server
Hello,
I'm having a problem which seems to be related to enqueueing Actions in a PoolFiber.
In a starting point of my Server code I instantiate the PoolFiber, and call Start(). For every HandleOperation(operation) variation in the Server code I call:
Fiber.Enqueue( () => SomeMethod(...) );

It works properly for almost all the operations, except one. For this specific operation handler (which does not work), the "SomeMethod()" is enqueued, but ignored. I've placed a debug in the first line of the method, but it is not written. The HandleOperation() for this operation is reached, and the operation/event logic seems to be exactly what I want.

Only this information may not be enough for you to guess what the problem might be, so I'll tell some more about the code structure. We organize our code paths with a State Machine Pattern. An operation which is handled in a state X may be invalid in a state Y. But the problematic operation is surely called in the state it should.

I have a guess about what may be causing this problem. A previous operation enqueues a method to change the system's state. The method instantiated the new state, and we place the PoolFiber in the upper State class, which means that every time we make this change, a new PoolFiber is created, and the previous one is discarded. My question about this is: Enqueueing a method which instantiates a new Fiber can cause bugs?
My Photon version is 3.2.10.4248, just in case it is a version bug...
Is PoolFiber the right class to control the flow of operations, or is there a better class for this?
I have no idea of what may be happening: if it is a fiber bug/limitation, if I'm doing something I shouldn't... I can only guess, by now.

Comments

  • chvetsov
    Options
    hi, vitorcmaia.
    it is difficutl to say what is wrong with your code, but defenetly something wrong in your code.
    PoolFiber does not have any limitations. It is good to control flow of your operations
  • So your flow is like this?

    1. fiber instance #1: enque method A
    2. fiber instance #1: enqueue method B
    3. fiber instance #1: execute method A => dispose fiber instance #1, instantiate fiber instance #2 (empty)

    And the problem is that method B is never executed? That would make sense because enqueued actions are not executed after a fiber is disposed.

    The solution would be to instantiate the fiber *once* when you enter the first state and re-use it between all states. The state class might not be the best place for the fiber at all. If your state classes represent the states of a peer, you might pass the peer into the state class and use the peer's fiber; if it represents the states of a game, you might add the fiber to the game class instead.

    Hope this helps!