Results 1 to 10 of 10

Thread: "QSocketNotifier: invalid socket 'Write' and type 26, disabling" What generates this?

  1. #1
    Join Date
    Aug 2009
    Posts
    140
    Thanks
    22
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default "QSocketNotifier: invalid socket 'Write' and type 26, disabling" What generates this?

    Hello,

    EDIT: See 1st reply for likely solution.

    I've seen this question get asked a lot but haven't found much of an answer beyond 'something is wrong with your sockets'. I've found this--thanks caduel--which says that 26 is likely an invalid file descriptor. How would an invalid descriptor come to be sent to a QSocketNotifier method? The socket in question is a QLocalSocket (one of two write sockets), and here is the code I use to send a message:

    Qt Code:
    1. void MyClass::WriteToLog(const string& msg, MY_MSG_TYPE type)
    2. {
    3. QDataStream out(&qb,QIODevice::WriteOnly);
    4. out << quint16(0) << quint8(type) << QString(msg.c_str());
    5. int num_bytes = qb.size() - sizeof(quint16); //Subtract four because in reading the
    6. //size information, the two bytes containing it are removed from the stream
    7. // Also sizeof(MY_MSG_TYPE) == 8
    8. out.device()->seek(0);
    9. out << quint16(num_bytes);
    10.  
    11. my_socket->write(qb);
    12. my_socket->flush();
    13. }
    To copy to clipboard, switch view to plain text mode 

    This seems to happen more frequently the more data I send through this socket, but I don't really send that much, maybe several hundred bytes every vertical refresh (60Hz), or ~50KB/sec tops to get this.

    I looked at the QSocketNotifier code and what I saw there confused me a little bit--

    Qt Code:
    1. QSocketNotifier::QSocketNotifier(int socket, Type type, QObject *parent,
    2. const char *name)
    3. : QObject(parent)
    4. {
    5. setObjectName(QString::fromAscii(name));
    6. if (socket < 0)
    7. qWarning("QSocketNotifier: Invalid socket specified");
    8. sockfd = socket;
    9. sntype = type;
    10. snenabled = true;
    11.  
    12. ...
    13. }
    To copy to clipboard, switch view to plain text mode 

    It doesn't return the complete error message, and in the message I do get, the socket descriptor is always >0, e.g. 24 or 26.

    Lastly, this crash is happening in a process launched from the one I launch using QtCreator, so I don't get any debugging output beyond what's in the subject line.

    Can anybody help me with this? Thank you--

    Best,
    Matt

  2. #2
    Join Date
    Aug 2009
    Posts
    140
    Thanks
    22
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: "QSocketNotifier: invalid socket 'Write' and type 26, disabling" What generates t

    Hello,

    So just as I was finishing that post it struck me that maybe the 'my_socket->flush();' command was the problem; according to Qt documentation it should be unnecessary. (Couldn't bring myself to just toss the post I just spent 45min composing though). I took it out, and now at least temporarily the problem seems to have disappeared. So perhaps this changes my question: Do I lose anything by taking that out? I want this information to be sent to the next process as quickly as possible, is it possible that other events will be processed before the QByteArray is sent?

    Matt
    Last edited by MattPhillips; 26th September 2010 at 16:58.

  3. #3
    Join Date
    Aug 2009
    Posts
    140
    Thanks
    22
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: "QSocketNotifier: invalid socket 'Write' and type 26, disabling" What generates t

    So this solution isn't a silver bullet after all. On Ubuntu, I'm finding that if I *don't* have a flush statement, messages aren't sent at all--even if mysocket->write(qb) is the last statement of the function. Anybody know what's up with this? The socket is a member of MyClass and is created with

    Qt Code:
    1. mysocket = new QLocalSocket();
    2. mysocket->connectToServer("myserver",QLocalSocket::WriteOnly);
    To copy to clipboard, switch view to plain text mode 

    Best,
    Matt

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: "QSocketNotifier: invalid socket 'Write' and type 26, disabling" What generates t

    Do you use any threading?

  5. #5
    Join Date
    Aug 2009
    Posts
    140
    Thanks
    22
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: "QSocketNotifier: invalid socket 'Write' and type 26, disabling" What generates t

    Hi tbscope,

    Yes. The process that is receiving these messages does so in a worker thread with its own event loop. The MyClass instance getting used is owned by the main thread, and WriteToLog is a slot. I call it directly (i.e. myclassinstance.WriteToLog(...)) from elsewhere in the main thread, and via a signal from a worker thread (that is also used for interprocess communication, but reads rather than writes). I'm using the default Qt::ConnectionType there.

    Best,
    Matt

  6. #6
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: "QSocketNotifier: invalid socket 'Write' and type 26, disabling" What generates t

    Are these Qt threads? (as in QThread)

  7. #7
    Join Date
    Aug 2009
    Posts
    140
    Thanks
    22
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: "QSocketNotifier: invalid socket 'Write' and type 26, disabling" What generates t

    That's frustrating, I posted a response to your comment 12 hours ago but it didn't show up in the thread. Anyway, yes these are Qt threads; and I have moveToThread(this) in the constructors and (of course) exec() at the end of the run() method.

    EDIT: Sometimes, though not always, I get error messages sent to cerr (which is sent to the main process before the auxiliary process crashes). Here are two examples, first the error messages (PEVS is the name of the process that crashes):

    cerr: *** glibc detected *** /home/matt/Projects/PEECS/build/../PEVS/build/PEVS: malloc(): smallbin double linked list corrupted: 0x0891d948 ***

    cerr: *** glibc detected *** /home/matt/Projects/PEECS/build/../PEVS/build/PEVS: malloc(): smallbin double linked list corrupted: 0x082cb8c8 ***
    And now error messages + partial backtrace:

    1)
    cerr: *** glibc detected *** /home/matt/Projects/PEECS/build/../PEVS/build/PEVS: malloc(): smallbin double linked list corrupted: 0x082cb8c8 ***
    ======= Backtrace: =========
    /lib/tls/i686/cmov/libc.so.6(+0x6b591)[0x1352591]
    /lib/tls/i686/cmov/libc.so.6(+0x6e710)[0x1355710]
    /lib/tls/i686/cmov/libc.so.6(__libc_malloc+0x5c)[0x1356f9c]
    /usr/lib/libstdc++.so.6(_Znwj+0x27)[0x1269c07]
    /home/matt/qtsdk-2010.04/qt/lib/libQtCore.so.4(_ZN9QMetaType9constructEiPKv+0x260)[0xfa4e20]
    /home/matt/qtsdk-2010.04/qt/lib/libQtCore.so.4(+0x196b72)[0xfacb72]
    /home/matt/qtsdk-2010.04/qt/lib/libQtCore.so.4(_ZN11QMetaObject8activateEP7QObject PKS_iPPv+0x14c)[0xfaf47c]
    /home/matt/Projects/PEECS/build/../PEVS/build/PEVS[0x80811c7]
    /home/matt/Projects/PEECS/build/../PEVS/build/PEVS[0x807a2d3]
    /home/matt/Projects/PEECS/build/../PEVS/build/PEVS[0x80813b3]
    /home/matt/qtsdk-2010.04/qt/lib/libQtCore.so.4(_ZN11QMetaObject8metacallEP7QObject NS_4CallEiPPv+0x5b)[0xf9f16b]
    /home/matt/qtsdk-2010.04/qt/lib/libQtCore.so.4(_ZN11QMetaObject8activateEP7QObject
    [...]
    2)
    cerr: *** glibc detected *** /home/matt/Projects/PEECS/build/../PEVS/build/PEVS: malloc(): smallbin double linked list corrupted: 0x0891d948 ***
    20:48:33.026: PEVS cerr: ======= Backtrace: =========
    20:48:33.028: PEVS cerr: /lib/tls/i686/cmov/libc.so.6(+0x6b591)[0x1352591]
    20:48:33.028: PEVS cerr: /lib/tls/i686/cmov/libc.so.6(+0x6e710)[0x1355710]
    20:48:33.030: PEVS cerr: /lib/tls/i686/cmov/libc.so.6(__libc_malloc+0x5c)[0x1356f9c]
    20:48:33.031: PEVS cerr: /usr/lib/libstdc++.so.6(_Znwj+0x27)[0x1269c07]
    20:48:33.031: PEVS cerr: /usr/lib/libstdc++.so.6(_ZNSs4_Rep9_S_createEjjRKSaIcE+0x66 )[0x1243d06]
    20:48:33.032: PEVS cerr: /home/matt/Projects/PEECS/build/../PEVS/build/PEVS[0x8072c7b]
    20:48:33.032: PEVS cerr: /home/matt/Projects/PEECS/build/../PEVS/build/PEVS[0x80557ef]
    20:48:33.032: PEVS cerr: /home/matt/Projects/PEECS/build/../PEVS/build/PEVS[0x8055a38]
    20:48:33.033: PEVS cerr: /home/matt/Projects/PEECS/build/../PEVS/build/PEVS[0x8076928]
    20:48:33.033: PEVS cerr: /home/matt/Projects/PEECS/build/../PEVS/build/PEVS[0x80544d2]
    20:48:33.034: PEVS cerr: /home/matt/Projects/PEECS/build/../PEVS/build/PEVS[0x8080f63]
    20:48:33.045: PEVS cerr: /home/matt/qtsdk-2010.04/qt/lib/libQtCore.so.4(_ZN11QMetaObject8metacallEP7QObject NS_4CallEiPPv+0x5b)[0xf9f16b]
    20:48:33.046: PEVS cerr: /home/matt/qtsdk-2010.04/qt/lib/libQtCore.so.4(_ZN14QMetaCallEvent13placeMetaCallE P7QObject+0x36)[0xfa93f6]
    20:48:33.048: PEVS cerr: /home/matt/qtsdk-2010.04/qt/lib/libQtCore.so.4(_ZN7QObject5eventEP6QEvent+0x198)[0xfaab68]
    20:48:33.049: PEVS cerr: /home/matt/qtsdk-2010.04/qt/lib/libQtGui.so.4(_ZN7QWidget5eventEP6QEvent+0x85)[0x3baec5]
    20:48:33.050: PEVS cerr: /home/matt/qtsdk-2010.04/qt/lib/libQtOpenGL.so.4(_ZN9QGLWidget5eventEP6QEvent+0x57 )[0x151ea7]
    20:48:33.051: PEVS cerr: /home/matt/qtsdk-2010.04/qt/lib/libQtGui.so.4(_ZN19QApplicationPrivate13notify_hel perEP7QObjectP6QEvent+0xbf)[0x35a4ff]
    20:48:33.052: PEVS cerr: /home/matt/qtsdk-2010.04/qt/lib/libQtGui.so.4(_ZN12QApplication6notifyEP7QObjectP6 QEvent+0x1ee)[0x35e10e]
    20:48:33.053: PEVS cerr: /home/matt/qtsdk-2010.04/qt/lib/libQtCore.so.4(_ZN16QCoreApplication14notifyIntern alEP7QObjectP6QEvent+0x7b)[0xf98b2b]
    20:48:33.053: PEVS cerr: /home/matt/qtsdk-2010.04/qt/lib/libQtCore.so.4(_ZN23QCoreApplicationPrivate16sendP ostedEventsEP7QObjectiP11QThreadData+0x1d1)[0xf99b91]
    20:48:33.065: PEVS cerr: /home/matt/qtsdk-2010.04/qt/lib/libQtCore.so.4(_ZN16QCoreApplication16sendPostedEv entsEP7QObjecti+0x2d)[0xf99e5d]
    20:48:33.066: PEVS cerr: /home/matt/qtsdk-2010.04/qt/lib/libQtCore.so.4(+0x1b019f)[0xfc619f]
    20:48:33.067: PEVS cerr: /lib/libglib-2.0.so.0(g_main_context_dispatch+0x1d5)[0x16815e5]
    20:48:33.067: PEVS cerr: /lib/libglib-2.0.so.0(+0x3f2d8)[0x16852d8]
    20:48:33.067: PEVS cerr: /lib/libglib-2.0.so.0(g_main_context_iteration+0x68)[0x16854b8]
    20:48:33.068: PEVS cerr: /home/matt/qtsdk-2010.04/qt/lib/libQtCore.so.4(_ZN20QEventDispatcherGlib13processE ventsE6QFlagsIN10QEventLoop17ProcessEventsFlagEE+0 x68)[0xfc64b8]
    20:48:33.068: PEVS cerr: /home/matt/qtsdk-2010.04/qt/lib/libQtGui.so.4(+0x2161d5)[0x4151d5]
    20:48:33.069: PEVS cerr: /home/matt/qtsdk-2010.04/qt/lib/libQtCore.so.4(_ZN10QEventLoop13processEventsE6QFl agsINS_17ProcessEventsFlagEE+0x4d)[0xf97bfd]
    20:48:33.069: PEVS cerr: /home/matt/qtsdk-2010.04/qt/lib/libQtCore.so.4(_ZN10QEventLoop4execE6QFlagsINS_17P rocessEventsFlagEE+0xbd)[0xf97f8d]
    20:48:33.070: PEVS cerr: /home/matt/qtsdk-2010.04/qt/lib/libQtCore.so.4(_ZN16QCoreApplication4execEv+0xac)[0xf99f1c]
    20:48:33.070: PEVS cerr: /home/matt/qtsdk-2010.04/qt/lib/libQtGui.so.4(_ZN12QApplication4execEv+0x27)[0x359c97]
    20:48:33.071: PEVS cerr: /home/matt/Projects/PEECS/build/../PEVS/build/PEVS[0x804f45c]
    20:48:33.071: PEVS cerr: /lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe6)[0x12fdbd6]
    20:48:33.075: PEVS cerr: /home/matt/Projects/PEECS/build/../PEVS/build/PEVS[0x804f2c1]
    Just in case the problem was allocating memory for the QByteArrays I use to write to the socket, I added reserve(1024) statements to every method that used the socket. Not surprisingly, this made no difference.

    Best,
    Matt
    Last edited by MattPhillips; 30th September 2010 at 03:38. Reason: Added information

  8. #8
    Join Date
    Aug 2009
    Posts
    140
    Thanks
    22
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: "QSocketNotifier: invalid socket 'Write' and type 26, disabling" What generates t

    Anyone have an idea?

  9. #9
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: "QSocketNotifier: invalid socket 'Write' and type 26, disabling" What generates t

    You have a pointer where you write beyond the boundaries of the pointer corrupting the heap.

  10. #10
    Join Date
    Aug 2009
    Posts
    140
    Thanks
    22
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: "QSocketNotifier: invalid socket 'Write' and type 26, disabling" What generates t

    Thanks tbscope. I've found that while I can't get rid of this error entirely, reducing traffic on that socket and putting the body of WriteToLog within a mutex allows me to avoid it, which is good enough for me for now. I don't understand how the problem could continue to exist once I've invoked a mutex (and WriteToLog is the only place where the socket is written to), but oh well...

Similar Threads

  1. Replies: 7
    Last Post: 8th November 2012, 12:26
  2. QSocketNotifier: Invalid socket 12 and type 'Read', disabling...
    By kunalnandi in forum General Programming
    Replies: 1
    Last Post: 24th September 2008, 19:09
  3. "Treat wchar_t as Built-in Type" to "yes" link error
    By sungaoyong in forum Qt Programming
    Replies: 1
    Last Post: 5th June 2008, 12:45
  4. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 20:05
  5. socket programming... getting "no route to host"
    By babusunlux in forum Qt Programming
    Replies: 1
    Last Post: 4th August 2006, 21:39

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.