Giter Club home page Giter Club logo

Comments (6)

skypjack avatar skypjack commented on May 18, 2024 1

I must admit that, although it actually makes sense, it would be probably a breaking change. I'm not sure it's the best choice.
On the other side, to solve the issue you pointed out it's enough to update the close member function as follows:

    void close() {
        auto err = uv_loop_close(loop.get());
        if(err) { publish(ErrorEvent{err}); }
        else { loop.reset(); }
    }

from uvw.

skypjack avatar skypjack commented on May 18, 2024

However uv_loop_close() is not idempotent (it will return UV_EBUSY if the loop has already been closed in DEBUG build, or crash straight away in Release build)

Interesting. Actually the documentation says something slightly different:

Call this function only when the loop has finished executing and all open handles and requests have been closed, or it will return UV_EBUSY.

It seems that UV_EBUSY is due to pending handles or requests instead.
Are you sure you've none of them?

from uvw.

skypjack avatar skypjack commented on May 18, 2024

In terms of consistency, the best bet is to remove the destructor of the loop and let it be a no-op.
uvw stays true to the behavior of libuv and you've eg to close handles explicitly, it won't close them for you. I don't see why it should close the loop implicitly.
I'm tempted to say that you pointed out a design issue rather then a bug.

from uvw.

Noisyfox avatar Noisyfox commented on May 18, 2024

It seems that UV_EBUSY is due to pending handles or requests instead.
Are you sure you've none of them?

The issue happens in debug mode because of this.

BTW for Release build the code that can reproduce this issue is even simpler:

int main()
{
	auto loop = uvw::Loop::create();
	loop->close();
}

image

I'm tempted to say that you pointed out a design issue rather then a bug.

My understanding is that if the loop contains any active handles / requests then there will be references to the loop so the destruction won't be called automatically, so the Loop::close() actually should not be called explicitly?

This seems quite reasonable since if the Loop get destructed but uv_loop_close() returns UV_EBUSY then that means something is wrong with the reference counter. In this case is not the fault of this library.

However this makes the Loop::close() function very confusing -- it's public but you are not supposed to call it.

from uvw.

skypjack avatar skypjack commented on May 18, 2024

Quite the opposite.

What I'm saying is that the Loop class should not invoke uv_loop_close. Actually, uvw::Loop should not have an explicitly defined destructor at all.
Instead, you as an user must close explicitly the loop as you would do if you were working directly with libuv. The same happens with the handles after all. This means staying true to the underlying library and that's why I think it's a design flaw rather than an issue.

from uvw.

Noisyfox avatar Noisyfox commented on May 18, 2024

Right that make sense.

from uvw.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.