Giter Club home page Giter Club logo

Comments (4)

sdroege avatar sdroege commented on July 20, 2024

Can you provide a small testcase that can be run to reproduce this?

from gio.

kevinpoitra avatar kevinpoitra commented on July 20, 2024

Sure thing - I've created a new repo for it, which can be found here. It works very similarly to what I posted above; it'll connect to one of GitHub's servers, try to send "test" as an array of bytes to it, and receive an error when trying to perform that write operation.

from gio.

sdroege avatar sdroege commented on July 20, 2024
diff --git a/src/main.rs b/src/main.rs
index 6e988d9..44454cc 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -41,6 +41,7 @@ fn main() {
                         })
                         .and_then(|(_strm, (_buf, count, _err))| {
                             dbg!(count);
+                            dbg!(stream);
                             Ok(())
                         })
                 })

This works around the problem. The problem is that stream, the gio::SocketConnection, is getting out of scope after your connect_to_host_async_future() continuation and is then destroyed. While you still have a reference to the gio::OutputStream, not having any reference to the connection anymore is causing it to be closed.

Quite unintuitive behaviour in gio, nothing to do with how the bindings work. You can easily reproduce it also with the following synchronous code:

use gio::prelude::*;

fn main() {
    let client = gio::SocketClient::new();
    client.set_timeout(10);

    let req = String::from("test");

    let conn = client.connect_to_host("192.30.253.112", 80, None::<&gio::Cancellable>).unwrap();

    println!("Is connected: {}", &conn.is_connected());
    println!("Stream is closed: {}", &conn.is_closed());
    let writer = conn.get_output_stream().expect("Failed to obtain output stream");

    // comment this out to make it work
    drop(conn);
    let res = writer.write_all(req.as_bytes(), None::<&gio::Cancellable>);
    println!("write finished: {:?}", res);
}

PS: Don't run a main context/main loop inside your startup signal handler. The gio::Application is already doing that for you and startup is called from an existing main loop.

from gio.

sdroege avatar sdroege commented on July 20, 2024

Reported to GLib: https://gitlab.gnome.org/GNOME/glib/issues/1690

Let's close this on our side then.

from gio.

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.