dicom / ruby-dicom

Library for reading, editing and writing DICOM files, as well as handling DICOM network communication. Written in the Ruby language.
http://dicom.rubyforge.org/
GNU General Public License v3.0
178 stars 67 forks source link

DICOM send broken pipe issue on OS X #28

Closed jeffmax closed 12 years ago

jeffmax commented 12 years ago

Are there any existing known issues with the DClient 'send' functionality?

I wrote a little script to use send to send the contents of a directory, but I keep getting this result:

INFO -- DICOM: Association successfully negotiated with host PACS
INFO -- DICOM: All 2 presentation contexts were accepted by host PACS
/Library/Ruby/Gems/1.8/gems/dicom-0.9.2/lib/dicom/link.rb:1092:in `send': Broken pipe - send(2) (Errno::EPIPE)
        from /Library/Ruby/Gems/1.8/gems/dicom-0.9.2/lib/dicom/link.rb:1092:in `transmit'
        from /Library/Ruby/Gems/1.8/gems/dicom-0.9.2/lib/dicom/d_client.rb:699:in `perform_send'
        from /Library/Ruby/Gems/1.8/gems/dicom-0.9.2/lib/dicom/d_client.rb:697:in `each'
        from /Library/Ruby/Gems/1.8/gems/dicom-0.9.2/lib/dicom/d_client.rb:697:in `perform_send'
        from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `each_with_index'
        from /Library/Ruby/Gems/1.8/gems/dicom-0.9.2/lib/dicom/d_client.rb:673:in `each'
        from /Library/Ruby/Gems/1.8/gems/dicom-0.9.2/lib/dicom/d_client.rb:673:in `each_with_index'
        from /Library/Ruby/Gems/1.8/gems/dicom-0.9.2/lib/dicom/d_client.rb:673:in `perform_send'
        from /Library/Ruby/Gems/1.8/gems/dicom-0.9.2/lib/dicom/d_client.rb:385:in `send'
        from ./dicom_push.rb:31
        from ./dicom_push.rb:28:in `foreach'
        from ./dicom_push.rb:28
jeffmax commented 12 years ago

PACS is dcm4chee 2.17.0, also tried with 2.15.0

dicom commented 12 years ago

Looking at the source code, the error happens when ruby-dicom tries to transmit a package:

@session.send(@outgoing.string, 0)

I think there are two possible explanations for what has happened:

  1. The server has (unexpectedly) terminated the connection prior to ruby-dicom trying to send data, and thus fails to send it.
  2. The TCPSocket network code of the Ruby library has crashed at this time on your system.

If it is 1, the cause may be that ruby-dicom has done something to upset your PACS at an earlier stage, and thus it aborts the connection. If so, it may be a regression. It would be helpful if you could try to determine this by testing the same thing with different versions of ruby-dicom, e.g. 0.9.2, 0.9.1, 0.8, 0.7.

If it is 2, then this may be a problem specific to the Ruby version and your system (OSX version). To debug this it would be helpful if you could try different ruby versions on your system, e.g. 1.8.7 vs 1.9.2, or even try it on another OS, like Windows or Linux.

jeffmax commented 12 years ago

Just wanted to let you know how great my experience has been with using this library so far. The c-find api was so easy to use in comparison to other tools I have tried.

I am working on the scenarios you described. Just to give you some more info, this is the stack trace from the PACS. I don't know if you have any experience with dcm4chee, but it appears to be a fairly informative for a Java exception:

2011-10-25 13:22:22,008 INFO  RUBY_DICOM->PACS (TCPServer-1-1) [org.dcm4chex.archive.dcm.storescp.StoreScpService] M-DELETE file:/data/d1/2011/10/25/13/28D15D36/B706D067/F6E5FA0E
2011-10-25 13:22:22,008 INFO  RUBY_DICOM->PACS (TCPServer-1-1) [org.dcm4cheri.net.FsmImpl] sending [pc-3] 1:C_STORE_RSP
    class:  1.2.840.10008.5.1.4.1.1.1/Computed Radiography Image Storage
    inst:   1.2.840.113564.10.1.37323423423342334232610/?
    status: 110
    error comment:  org.dcm4che.net.PDUException: Unrecognized PDU[type=254, length=
2011-10-25 13:22:22,009 WARN  -> (TCPServer-1-1) [org.dcm4cheri.util.LF_ThreadPool] Exception thrown in TCPServer-1-1
java.lang.IllegalStateException
    at org.dcm4cheri.net.FsmImpl$State.write(FsmImpl.java:920)
    at org.dcm4cheri.net.FsmImpl.write(FsmImpl.java:601)
    at org.dcm4cheri.net.DimseWriterImpl.flushPDataTF(DimseWriterImpl.java:106)
    at org.dcm4cheri.net.DimseWriterImpl.write(DimseWriterImpl.java:97)
    at org.dcm4cheri.net.AssociationImpl.write(AssociationImpl.java:327)
    at org.dcm4che.net.DcmServiceBase.c_store(DcmServiceBase.java:122)
    at org.dcm4cheri.net.ActiveAssociationImpl.run(ActiveAssociationImpl.java:223)
    at org.dcm4cheri.util.LF_ThreadPool.join(LF_ThreadPool.java:174)
    at org.dcm4cheri.net.ActiveAssociationImpl.run(ActiveAssociationImpl.java:157)
    at org.dcm4cheri.server.DcmHandlerImpl.handle(DcmHandlerImpl.java:249)
    at org.dcm4cheri.server.ServerImpl.run(ServerImpl.java:279)
    at org.dcm4cheri.util.LF_ThreadPool.join(LF_ThreadPool.java:174)
    at org.dcm4cheri.util.LF_ThreadPool$1.run(LF_ThreadPool.java:221)
    at java.lang.Thread.run(Thread.java:619)
jeffmax commented 12 years ago

I upgraded ruby to 1.9.2 (was on 1.8.7) and it worked on both centos and Mac OS X.

dicom commented 12 years ago

Actually, I suspect this is an issue with ruby-dicom version 0.9.2 and ruby 1.8, as described here: https://groups.google.com/forum/#!topic/ruby-dicom/rU80DA_8HQ4

I suspect you'll be fine with ruby-dicom 0.9.1 on ruby 1.8.7, and as you've confirmed, gem version 0.9.2 on ruby 1.9.2.

Although, looking at your error log, Im somewhat mystified by the 'unrecognized PDU' message.

Thanks for your comments on the friendly API by the way!