<div dir="ltr">Thanks Richard!<br>The patches are similar to what we did locally, and applying them fixed the issue with the actual use-case (not just the sanitized repro).</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Feb 14, 2023 at 8:10 PM Richard W.M. Jones <<a href="mailto:rjones@redhat.com">rjones@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Tue, Feb 14, 2023 at 08:02:59PM +0200, Yonatan Shtarkman wrote:<br>
> The attached code snippet reproduces the issue when running:<br>
> python3 libugestfs_segfault_repro.py<br>
> <br>
> With:<br>
> guestfs version: 1.48.6<br>
> guestfs-python version: 1.48.6<br>
<br>
Can confirm with {python3-,}libguestfs-1.51.1-1.fc39.x86_64<br>
<br>
The stack trace is roughly the same as yours.<br>
<br>
Rich.<br>
<br>
> Stacktrace:<br>
> #0 0x00007f6dd17b4701 in _Py_INCREF (op=<optimized out>) at /usr/include/<br>
> python3.9/object.h:408<br>
> 408 op->ob_refcnt++;<br>
> (gdb) bt<br>
> #0 0x00007f6dd17b4701 in _Py_INCREF (op=<optimized out>) at /usr/include/<br>
> python3.9/object.h:408<br>
> #1 guestfs_int_py_event_callback_wrapper<br>
> (g=<optimized out>, flags=<optimized out>, array_len=0, array=0x0, buf_len=<br>
> 43, buf=0xd1dc90 "commandrvf: udevadm --debug settle -E /\347\232\204\303<br>
> available\r\ned7<br>
> #2 guestfs_int_py_event_callback_wrapper<br>
> (g=<optimized out>, callback=0x7f6dd19ec040, event=16, event_handle=0,<br>
> flags=<optimized out>, buf=0xd1dc90 "commandrvf: udevadm --debug settle -E /\<br>
> 347\232\204\303 4<br>
> #3 0x00007f6dd166f9aa in guestfs_int_call_callbacks_message<br>
> (g=0xae06f0, event=16, buf=0xd1dc90 "commandrvf: udevadm --debug settle -E<br>
> /\347\232\204\303 available\r\ned to rvf:e run in, ignor data av", buf_len=43)<br>
> at events.c:117<br>
> #4 0x00007f6dd168560e in guestfs_int_log_message_callback<br>
> (g=g@entry=0xae06f0, buf=0xd1dc90 "commandrvf: udevadm --debug settle -E /\<br>
> 347\232\204\303 available\r\ned to rvf:e run in, ignor data av", len=len@entry<br>
> =43)<br>
> at proto.c:145<br>
> #5 0x00007f6dd166ac29 in handle_log_message (g=g@entry=0xae06f0, conn=<br>
> conn@entry=0xd19570) at conn-socket.c:395<br>
> #6 0x00007f6dd166b233 in read_data (len=4, bufv=<optimized out>, connv=<br>
> <optimized out>, g=<optimized out>) at conn-socket.c:179<br>
> #7 read_data (g=0xae06f0, connv=0xd19570, bufv=<optimized out>, len=4) at<br>
> conn-socket.c:142<br>
> #8 0x00007f6dd1685c2a in recv_from_daemon (buf_rtn=0x7fffa95cc548, size_rtn=<br>
> 0x7fffa95cc544, g=0xae06f0) at proto.c:545<br>
> #9 guestfs_int_recv_from_daemon (g=g@entry=0xae06f0, size_rtn=size_rtn@entry=<br>
> 0x7fffa95cc544, buf_rtn=buf_rtn@entry=0x7fffa95cc548) at proto.c:623<br>
> #10 0x00007f6dd168603a in guestfs_int_recv<br>
> (g=g@entry=0xae06f0, fn=fn@entry=0x7f6dd16aa308 "download", hdr=hdr@entry=<br>
> 0x7fffa95cc610, err=err@entry=0x7fffa95cc5e0, xdrp=xdrp@entry=0x0, ret=<br>
> ret@entry=0x0)<br>
> at proto.c:668<br>
> #11 0x00007f6dd163825e in guestfs_download (g=g@entry=0xae06f0, remotefilename=<br>
> <optimized out>, filename=0x7f6dd17edea0 "/tmp/1") at actions-5.c:2984<br>
> #12 0x00007f6dd17ab01a in guestfs_int_py_download (self=<optimized out>, args=<br>
> <optimized out>) at actions-5.c:794<br>
> <br>
> <br>
> <br>
> On Mon, Feb 13, 2023 at 10:16 PM Richard W.M. Jones <<a href="mailto:rjones@redhat.com" target="_blank">rjones@redhat.com</a>> wrote:<br>
> <br>
> On Mon, Feb 13, 2023 at 09:38:50PM +0200, Yonatan Shtarkman wrote:<br>
> > Also, as a workaround, I avoided calling the event callback if null is<br>
> returned<br>
> > by Py_BuildValue (still print the error and release the thread).<br>
> > This seems to work for our usage (we only use the event callbacks for<br>
> logging),<br>
> > any potential issues I'm missing?<br>
> <br>
> Oh I see so the issue is actually when logging and not in the download<br>
> call? That's strange that it should be happening intermittently. I'd<br>
> expect a UTF-8 encoding error would happen every time not sometimes.<br>
> <br>
> Rich.<br>
> <br>
> --<br>
> Richard Jones, Virtualization Group, Red Hat <a href="http://people.redhat.com/" rel="noreferrer" target="_blank">http://people.redhat.com/</a><br>
> ~rjones<br>
> Read my programming and virtualization blog: <a href="http://rwmj.wordpress.com" rel="noreferrer" target="_blank">http://rwmj.wordpress.com</a><br>
> virt-top is 'top' for virtual machines. Tiny program with many<br>
> powerful monitoring features, net stats, disk stats, logging, etc.<br>
> <a href="http://people.redhat.com/~rjones/virt-top" rel="noreferrer" target="_blank">http://people.redhat.com/~rjones/virt-top</a><br>
> <br>
> <br>
<br>
> import guestfs<br>
> from guestfs import GuestFS<br>
> <br>
> g = GuestFS(python_return_dict=True)<br>
> def callback(event, _event_handle, buf: str, array):<br>
> pass<br>
> <br>
> g.set_event_callback(callback, guestfs.EVENT_ALL)<br>
> g.set_verbose(True)<br>
> path = '/tmp/tmp_disk'<br>
> g.disk_create(path, format='raw', size=32*1024*1024)<br>
> g.add_drive(path)<br>
> g.launch()<br>
> g.mkfs('ext4', '/dev/sda')<br>
> g.mount('/dev/sda', '/')<br>
> for _ in range(20000):<br>
> try:<br>
> g.download ('/的ó', '/tmp/1')<br>
> except:<br>
> pass<br>
> <br>
<br>
<br>
-- <br>
Richard Jones, Virtualization Group, Red Hat <a href="http://people.redhat.com/~rjones" rel="noreferrer" target="_blank">http://people.redhat.com/~rjones</a><br>
Read my programming and virtualization blog: <a href="http://rwmj.wordpress.com" rel="noreferrer" target="_blank">http://rwmj.wordpress.com</a><br>
virt-builder quickly builds VMs from scratch<br>
<a href="http://libguestfs.org/virt-builder.1.html" rel="noreferrer" target="_blank">http://libguestfs.org/virt-builder.1.html</a><br>
<br>
</blockquote></div>