-
Notifications
You must be signed in to change notification settings - Fork 298
Multiple instances of Event class for the same event cause events being missed #2323
Comments
I'm away at the mo (and really I'm not the best person to answer this anyways), but one thing I thought I should mention in case you don't know is that Oni does spawn multiple instances of Neovim. That is, we have the main instance that we use for the editor, but there is also a second instance that is shared by all the UI. The explorer and more use it in their back end so that movements etc all work as expected and more. I think that at least explains the differene between the Neovim Editor (main editor instance) and the SharedNeovimInstance (shared across the UI). There is the possibility with the upcoming PRs on Neovim core for multiple windows that we'd be able to remove that, but currently its not the case, and potentially still not wanted (ie having a clean neovim instance is nice since we can not load any config etc, so plugins can't break the UI). This potentially gets more complicated when you consider the "Oni split mode" shown over in #1682. That is, having multiple instances of the Neovim editor class, which may help explain a bit of the other parts of the design. I'm also unable to reproduce any errors in the console, though I'm not running Nvim 0.3.0 on my laptop and am on Windows, so when I'm home I can test both on my Arch box for a bit of a better representation. |
Well since multiple instances of neovim are ok, the event system is at fault then. Then into On my machine I get this: This of course causes #2250 and probably more parts of the application to break. |
@CrossR did you check into this by any chance? |
Oops nope, I've just got back home today, so could possibly have a look later today. Its probably also worth seeing if @bryphe has any insights since he wrote these parts I think, and is more aware of the ongoing architecture to support multiple Nvim instances and such. |
@GeorgeTG thanks for raising this seems like an issue with the
I think we would love to have a PR (only if your up for it no pressure of course if really great to have your investigation as its a really good jumping off point for anyone to tackle this), the |
Well if all constructors get an event name, then |
By the way @Akin909 I'm wondering why does a 44 line file needs its own repo. Doesn't that make development a bit more complicated? |
@GeorgeTG I believe the long term idea behind it is to keep oni-core lean and modular and separate out different bits to be worked on in isolation to prevent core from becoming a monolith (@bryphe would be a better person to answer questions about the architectural path for oni, cheekily @'ing him although his is quite busy so might not be able to respond here, hopefully I've done it justice) |
Okay I've changed all constructors to pass EventNames #2355 . |
Do you have a callstack for this, or a custom configuration that uses If you could share your
The events should not be singletons. We support having multiple editor instances, and as such, each editor instance should have its own Here's an example - I have I then hook up separate event handlers: This allows me to specifically work with a particular editor - it's useful if I need to add ephemeral hooks. I didn't show this in the gif - but if I just want to subscribe to buffer enter events across the board, I could use: Hope that helps explain the behavior a bit.
I use this code in other projects. I'd be open to bringing it here as long as we can still publish it as a separate npm package. |
I just clone oni and build it, I have no config.tsx so I guess the defaults are loaded. |
Thanks @GeorgeTG for the screen capture! That's very helpful. Looks like it's crashing here oni/browser/src/Services/Browser/index.tsx Line 177 in 7c09bcf
Which is called by: oni/browser/src/Services/Browser/index.tsx Line 194 in 7c09bcf
It seems like the
So something is busted along that pipeline - not sure where it is breaking down. It would be useful to know where it gets to, by putting breakpoints in. We can also make calls to the
I'm wondering if somehow |
I went over this in the original post. Tldr: The problem is that there are two instances of the events. Subscribe is called in one and events are emitted from the other. Check the post for details. |
Two instances of events are expected - there are two There is definitely something going wrong here in the pipeline that I outlined above - but having two event instances is not the root cause. There's something specifically going wrong with the event handling from Note that - we don't see this get hit in any of our CiTests, and I can't repro it locally on Mac / Windows - so I believe there is at least something specific to your configuration that's triggering it. It would be a helpful / interesting data point if anyone else is hitting this, though! Keep in mind, if this actually was a general issue with the event system, we'd see it reproduce in our automation (based on your gif... it's unfortunately really easy to repro on your machine!) |
Oni Version: 0.3.4 and 0.3.5 from latest git
Neovim Version (Linux only): 0.3.0
Operating System: Arch-Linux
Describe your issue
When navigating with j,k a lot of errors are thrown in the console window because
editorManager.activeEditor.activeBuffer.
is null.This happens because NeovimEditor's lastBufferId is null which in turn happens because
onBufEnter event is seemingly never called.
Now that is the part things get complicated.
Event handling happens through oni-types Event class.
So the oni-types Event class instantiates a new EventEmitter for each instance of the Event class.
Because of this for subscribe and dispatch to work, the same instance of the Event class must be used by the subscriber(s) and the dispatcher(s) basically meaning that all events must be singletons, although no measures are taken to enforce this.
(This behaviour also eliminates the need for the name parameter, since it is ignored and not used anyway.)
Of course if the name argument was provided for all events a single EventEmitter would be enough and the whole problem would be "patched", but the core of the problem is not the Event system by itself.
In the current state of the code, some events have two instances. One instance is dispatching, while the Editor is subscribed to the other. As of now I'm pretty sure that this happens with atleast all NeovimAutoCommands/Editor related Events.
A NeovimAutoCommands instance is created only in NeovimInstance.
Now things get even more complicated and confusing.
Two NeovimInstance instances are created that result in two NeovimProcessSpawner::startNeovim calls which basically runs nvim two times and I'm not sure if this is intended. Again it looks like NeovimInstance should be a singleton, but it isn't.
The first NeovimInstance is created in NeovimEditor which is a SuperClass of OniEditor and is instantiated in startEditors.
The second one is created in SharedNeovimInstance which is a NeovimInstance wrapper.
Now both startEditors and SharedNeovimInstance reside in App.ts so I guess the intended behaviour would be to pass the SharedNeovimInstance's NeovimInstance to startEditors or something similar.
I would make a PR but I'm not sure how to proceed since the intended behaviour is not that clear with this.
Expected behaviour
Events handled and program working smoothly.
Actual behaviour
Hundreds of errors spamming the console and at least all NeovimAutoCommand events are missed.
Steps to reproduce
Open any file, navigate with j,k in visual mode, with developer tools open.
The text was updated successfully, but these errors were encountered: