archive_read_open1 hangs indefinitely

13 views
Skip to first unread message

vanessa...@iohk.io

unread,
Mar 26, 2019, 10:58:18 PM3/26/19
to libarchive-discuss
Hi all,

I have been trying to get lazy streaming with libarchive working in Haskell. My code follows:

-- | Lazily stream a 'BSL.ByteString'
bslToArchive
:: BSL.ByteString -> IO (Ptr Archive)
bslToArchive bs
= do
    a
<- archive_read_new
   
void $ archive_read_support_format_all a
    bsChunksRef
<- newIORef bsChunks
    rc
<- mkReadCallback (readBSL bsChunksRef)
    cc
<- mkCloseCallback (\_ ptr -> free ptr $> archiveOk)
    nothingPtr
<- mallocBytes 0
    sequence_
[ archive_read_set_read_callback a rc
             
, archive_read_set_close_callback a cc
             
, archive_read_set_callback_data a nothingPtr
             
-- this is where it hangs indefinitely
             
, archive_read_open1 a
             
]
    pure a
   
where readBSL bsRef _ _ dataPtr = do
                bs
' <- readIORef bsRef
                case bs'
of
                   
[] -> pure 0
                   
(x:_) -> do
                        modifyIORef bsRef tail
                        useAsCStringLen x $
\(charPtr, sz) ->
                            poke dataPtr charPtr $
>
                            fromIntegral sz
          bsChunks
= BSL.toChunks bs

Unfortunately, this hangs indefinitely upon the call to archive_read_open1(I know this from print-debugging). Somewhat curiously, memory consumption remains constant and CPU usage remains low though nothing happens.

I have a feeling I have done something wrong: are there any known circumstances in which a call to archive_read_open1 will result in an infinite loop that consumes no CPU?

The full code is here https://github.com/vmchale/libarchive if interested. 

Thanks,
Vanessa McHale

Vanessa McHale

unread,
Mar 27, 2019, 12:13:36 PM3/27/19
to libarchiv...@googlegroups.com

Upon further investigation, it appears that the Haskell functions to create function pointers are somehow fucked (hence the indefinite hanging with no CPU use). Thus, I do not believe it is triggered by any infinite loop in archive_read_open1 itself.

Cheers,
Vanessa McHale

--
You received this message because you are subscribed to the Google Groups "libarchive-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to libarchive-disc...@googlegroups.com.
To post to this group, send email to libarchiv...@googlegroups.com.
Visit this group at https://groups.google.com/group/libarchive-discuss.
For more options, visit https://groups.google.com/d/optout.
signature.asc
Reply all
Reply to author
Forward
0 new messages