[spice-gtk] spice-channel: return if has_error is TRUE in spice_channel_write_msg

Submitted by Jakub Janku on June 26, 2019, 8:02 a.m.

Details

Message ID 20190626080222.8434-1-jjanku@redhat.com
State New
Headers show
Series "spice-channel: return if has_error is TRUE in spice_channel_write_msg" ( rev: 1 ) in Spice

Not browsing as part of any series.

Commit Message

Jakub Janku June 26, 2019, 8:02 a.m.
Avoid linearizing if the message isn't written out anyway
(spice_channel_flush_wire checks() this condition as well).

This also silences the following error:

    (spicy:32087): GSpice-CRITICAL **: 16:22:03.147: spice_session_get_read_only: assertion 'SPICE_IS_SESSION(self)' failed

that can be seen if the channel gets disconnected
by the session while having non-empty write queue.

spice_session_channel_destroy() sets channel->priv->session to NULL,
but spice_channel_write_msg() subsequently attempts to call
spice_session_get_read_only() with NULL pointer.

Signed-off-by: Jakub Janků <jjanku@redhat.com>
---
 src/spice-channel.c | 5 +++++
 1 file changed, 5 insertions(+)

Patch hide | download patch | download mbox

diff --git a/src/spice-channel.c b/src/spice-channel.c
index 61de177..aa80edf 100644
--- a/src/spice-channel.c
+++ b/src/spice-channel.c
@@ -897,6 +897,11 @@  static void spice_channel_write_msg(SpiceChannel *channel, SpiceMsgOut *out)
     g_return_if_fail(out != NULL);
     g_return_if_fail(channel == out->channel);
 
+    if (channel->priv->has_error) {
+        spice_msg_out_unref(out);
+        return;
+    }
+
     if (out->ro_check &&
         spice_channel_get_read_only(channel)) {
         g_warning("Try to send message while read-only. Please report a bug.");

Comments

> 
> Avoid linearizing if the message isn't written out anyway

"linearizing" ? What do you mean about that?
Looking at definitions it seems not correct to me.

> (spice_channel_flush_wire checks() this condition as well).
> 
> This also silences the following error:
> 
>     (spicy:32087): GSpice-CRITICAL **: 16:22:03.147:
>     spice_session_get_read_only: assertion 'SPICE_IS_SESSION(self)' failed
> 
> that can be seen if the channel gets disconnected
> by the session while having non-empty write queue.
> 
> spice_session_channel_destroy() sets channel->priv->session to NULL,
> but spice_channel_write_msg() subsequently attempts to call
> spice_session_get_read_only() with NULL pointer.
> 

Minor: this is the explanation why the error on the previous
paragraph should not be treated like an error, I think it should
be the same paragraphs.

OT: maybe channel session should never be NULL?

> Signed-off-by: Jakub Janků <jjanku@redhat.com>
> ---
>  src/spice-channel.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/src/spice-channel.c b/src/spice-channel.c
> index 61de177..aa80edf 100644
> --- a/src/spice-channel.c
> +++ b/src/spice-channel.c
> @@ -897,6 +897,11 @@ static void spice_channel_write_msg(SpiceChannel
> *channel, SpiceMsgOut *out)
>      g_return_if_fail(out != NULL);
>      g_return_if_fail(channel == out->channel);
>  
> +    if (channel->priv->has_error) {
> +        spice_msg_out_unref(out);
> +        return;
> +    }
> +
>      if (out->ro_check &&
>          spice_channel_get_read_only(channel)) {
>          g_warning("Try to send message while read-only. Please report a
>          bug.");

Frediano
Hi,

On Thu, Jun 27, 2019 at 10:10 AM Frediano Ziglio <fziglio@redhat.com> wrote:
>
> >
> > Avoid linearizing if the message isn't written out anyway
>
> "linearizing" ? What do you mean about that?
> Looking at definitions it seems not correct to me.

I was simply referring to the spice_marshaller_linearize() call.
>
> > (spice_channel_flush_wire checks() this condition as well).
> >
> > This also silences the following error:
> >
> >     (spicy:32087): GSpice-CRITICAL **: 16:22:03.147:
> >     spice_session_get_read_only: assertion 'SPICE_IS_SESSION(self)' failed
> >
> > that can be seen if the channel gets disconnected
> > by the session while having non-empty write queue.
> >
> > spice_session_channel_destroy() sets channel->priv->session to NULL,
> > but spice_channel_write_msg() subsequently attempts to call
> > spice_session_get_read_only() with NULL pointer.
> >
>
> Minor: this is the explanation why the error on the previous
> paragraph should not be treated like an error, I think it should
> be the same paragraphs.

Makes sense.
>
> OT: maybe channel session should never be NULL?

It indeed does seem weird that
g_clear_object(&channel->priv->session); is called when the
"spice-session" property of the channel is G_PARAM_CONSTRUCT_ONLY --
with this flag, I would expect the property to not change after the
construction.

Spice session waits for the channel destruction anyway
(channel_finally_destroyed callback), so it should be imho fine that
the channel holds a reference to the session while it is being
destroyed. So I think we could remove that
g_clear_object(&channel->priv->session); call in
spice_session_channel_destroy().
>
> > Signed-off-by: Jakub Janků <jjanku@redhat.com>
> > ---
> >  src/spice-channel.c | 5 +++++
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/src/spice-channel.c b/src/spice-channel.c
> > index 61de177..aa80edf 100644
> > --- a/src/spice-channel.c
> > +++ b/src/spice-channel.c
> > @@ -897,6 +897,11 @@ static void spice_channel_write_msg(SpiceChannel
> > *channel, SpiceMsgOut *out)
> >      g_return_if_fail(out != NULL);
> >      g_return_if_fail(channel == out->channel);
> >
> > +    if (channel->priv->has_error) {
> > +        spice_msg_out_unref(out);
> > +        return;
> > +    }
> > +
> >      if (out->ro_check &&
> >          spice_channel_get_read_only(channel)) {
> >          g_warning("Try to send message while read-only. Please report a
> >          bug.");
>
> Frediano
> 
> Hi,
> 
> On Thu, Jun 27, 2019 at 10:10 AM Frediano Ziglio <fziglio@redhat.com> wrote:
> >
> > >
> > > Avoid linearizing if the message isn't written out anyway
> >
> > "linearizing" ? What do you mean about that?
> > Looking at definitions it seems not correct to me.
> 
> I was simply referring to the spice_marshaller_linearize() call.

So maybe:

"Avoid calling spice_marshaller_linearize() if the message isn't written out
anyway (spice_channel_flush_wire checks() this condition as well)."

surely tomorrow I won't remember what you explained.

> >
> > > (spice_channel_flush_wire checks() this condition as well).
> > >
> > > This also silences the following error:
> > >
> > >     (spicy:32087): GSpice-CRITICAL **: 16:22:03.147:
> > >     spice_session_get_read_only: assertion 'SPICE_IS_SESSION(self)'
> > >     failed
> > >
> > > that can be seen if the channel gets disconnected
> > > by the session while having non-empty write queue.
> > >
> > > spice_session_channel_destroy() sets channel->priv->session to NULL,
> > > but spice_channel_write_msg() subsequently attempts to call
> > > spice_session_get_read_only() with NULL pointer.
> > >
> >
> > Minor: this is the explanation why the error on the previous
> > paragraph should not be treated like an error, I think it should
> > be the same paragraphs.
> 
> Makes sense.
> >
> > OT: maybe channel session should never be NULL?
> 
> It indeed does seem weird that
> g_clear_object(&channel->priv->session); is called when the
> "spice-session" property of the channel is G_PARAM_CONSTRUCT_ONLY --
> with this flag, I would expect the property to not change after the
> construction.
> 
> Spice session waits for the channel destruction anyway
> (channel_finally_destroyed callback), so it should be imho fine that
> the channel holds a reference to the session while it is being
> destroyed. So I think we could remove that
> g_clear_object(&channel->priv->session); call in
> spice_session_channel_destroy().

Surely there's a reason for this reset but you agree it does
not sound entirely right.

> >
> > > Signed-off-by: Jakub Janků <jjanku@redhat.com>
> > > ---
> > >  src/spice-channel.c | 5 +++++
> > >  1 file changed, 5 insertions(+)
> > >
> > > diff --git a/src/spice-channel.c b/src/spice-channel.c
> > > index 61de177..aa80edf 100644
> > > --- a/src/spice-channel.c
> > > +++ b/src/spice-channel.c
> > > @@ -897,6 +897,11 @@ static void spice_channel_write_msg(SpiceChannel
> > > *channel, SpiceMsgOut *out)
> > >      g_return_if_fail(out != NULL);
> > >      g_return_if_fail(channel == out->channel);
> > >
> > > +    if (channel->priv->has_error) {
> > > +        spice_msg_out_unref(out);
> > > +        return;
> > > +    }
> > > +
> > >      if (out->ro_check &&
> > >          spice_channel_get_read_only(channel)) {
> > >          g_warning("Try to send message while read-only. Please report a
> > >          bug.");
> >
> > Frediano
>