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

assert failed in processLimit #50

Open
penfree opened this issue Sep 22, 2023 · 10 comments
Open

assert failed in processLimit #50

penfree opened this issue Sep 22, 2023 · 10 comments

Comments

@penfree
Copy link

penfree commented Sep 22, 2023

I got an exception and the program crashed, i don't really know how to reproduce it, it is not triggered by a special parameter. would you please help me to figure it out. @gelldur

  • The error log:
    /thirdparty/EventBus-3.0.4/lib/src/dexode/EventBus.cpp:57: std::size_t dexode::EventBus::processLimit(std::size_t): Assertion `removeFrom != _eventStreams.end()' failed.

  • The source code is here:

	{
		std::lock_guard writeGuard{_mutexStreams};
		if(!_eventStreams.empty())
		{
			// If anything was added then we need to add those elements
			std::move(_eventStreams.begin(), _eventStreams.end(), std::back_inserter(eventStreams));
		}
		std::swap(eventStreams, _eventStreams); // move data TO member

		// Check do we need remove something
		if(_eventStreams.size() != _eventToStream.size())
		{
			auto removeFrom = std::remove_if(
				_eventStreams.begin(), _eventStreams.end(), [this](const auto& eventStream) {
					for(const auto& element : _eventToStream)
					{
						// Don't remove if we point to the same place (is it UB ?)
						if(element.second == eventStream.get())
						{
							return false;
						}
					}
					return true;
				});
			assert(removeFrom != _eventStreams.end());
			_eventStreams.erase(removeFrom, _eventStreams.end());
		}
	}
@penfree
Copy link
Author

penfree commented Sep 22, 2023

i have gdb into the core.

(gdb) p _eventStreams
$1 = std::vector of length 0, capacity 0
(gdb) p _eventToStream
$2 = std::map with 3 elements = {
  [0x55fad188f928 <dexode::eventbus::internal::type_id_ptr<dolphin::StreamAddEvent>::id>] = 0x55fad26f2510,
  [0x55fad18907f8 <dexode::eventbus::internal::type_id_ptr<dolphin::StreamRemoveEvent>::id>] = 0x55fad26af030,
  [0x55fad1891a48 <dexode::eventbus::internal::type_id_ptr<dolphin::StreamStatusChangeEvent>::id>] = 0x7f4644005fa0}
(gdb) quit

@gelldur
Copy link
Owner

gelldur commented Sep 22, 2023

Hello, could you send more ? I mean parts of your code? I will try to check again this part of code. Thanks.
Some questions:

  1. Do you use EventBus in multithreaded environment ? (Send events in one thread, process in another)
  2. Do you call process() in multiple threads?

@penfree
Copy link
Author

penfree commented Sep 22, 2023

Hello, could you send more ? I mean parts of your code? I will try to check again this part of code. Thanks. Some questions:

  1. Do you use EventBus in multithreaded environment ? (Send events in one thread, process in another)
  2. Do you call process() in multiple threads?
  1. yes, i use it in multithreaded environment.
  2. yes, every threads postpone and process immediately。

the code is almost the same as readme, except it is called in multithread environment.

@gelldur
Copy link
Owner

gelldur commented Sep 22, 2023

Overall there should be only 1 thread that consumes ( calls process() ). You can send events from any thread ( calling postpone(Event) ). I will try write test for your use-case. I think I didn't tested it like that.

Usually you have 1 consumer thread for example main thread that will process events and call your listeners. Thanks to that you always know on what thread you listeners would be executed.

@penfree
Copy link
Author

penfree commented Sep 22, 2023

Overall there should be only 1 thread that consumes ( calls process() ). You can send events from any thread ( calling postpone(Event) ). I will try write test for your use-case. I think I didn't tested it like that.

oh, that is not easy to do. so i should use a cycle thread to consume the events?

@gelldur
Copy link
Owner

gelldur commented Sep 22, 2023

Ok nvm, I will create test for this. Maybe there is a bug.

In source code I see there is already mutex for "single process"

std::lock_guard writeGuardProcess{_mutexProcess}; // Only one process at the time

@penfree
Copy link
Author

penfree commented Sep 22, 2023

Ok nvm, I will create test for this. Maybe there is a bug.

In source code I see there is already mutex for "single process"

std::lock_guard writeGuardProcess{_mutexProcess}; // Only one process at the time

emm, i saw that too, so maybe mutex is missed somewhere. i found that when call frequency is slow, it works well

@gelldur
Copy link
Owner

gelldur commented Sep 22, 2023

Thanks, I will find issue and fix it soon (I will try this weekend). My best guess for now that there is some data race between process() and postpone()

@penfree
Copy link
Author

penfree commented Oct 25, 2023

@gelldur is there any progress?

@gelldur
Copy link
Owner

gelldur commented Oct 25, 2023

Sorry didn't have time. I will try soon. If you find solution It would be nice to merge your PR :)

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

No branches or pull requests

2 participants