# TCPSocket.flush lockup

**URL:** <https://forum.xojo.com/t/tcpsocket-flush-lockup/34677>\
**Category:** General\
**Created:** [November 28, 2016, 11:46pm UTC](https://forum.xojo.com/t/tcpsocket-flush-lockup/34677 "2016-11-28T23:46:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Graham](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/b38774/32.png) [@David\_Graham](https://forum.xojo.com/u/David_Graham)\
**Post date:** [November 28, 2016, 11:46pm UTC](https://forum.xojo.com/t/tcpsocket-flush-lockup/34677/1 "2016-11-28T23:46:48Z")

</div>

I just squashed a bug that had eluded me for several days - code that had been working fine for years started locking up the application, apparently randomly and intermittantly, w/o firing an app.unhandledexception. It’s running on OS 10.8 using Xojo 2015v3. It was a pain to track down because the IDE would lock up, so it was difficult to track down. It turned out the code was locking up at TPCsocket.flush, in code talking to a Keithley voltmeter. Removing that flush stopped the hangups. Is this a bug in Xojo? Why would this crash the IDE? Does it require a response from the receiving end?

---

<div class="post-metadata">

**Author:** ![Joe\_Ranieri](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/43a26b/32.png) [@Joe\_Ranieri](https://forum.xojo.com/u/Joe_Ranieri)\
**Post date:** [December 17, 2016, 2:26pm UTC](https://forum.xojo.com/t/tcpsocket-flush-lockup/34677/2 "2016-12-17T14:26:37Z")

</div>

TCPSocket.Flush is basically implemented like this:

```auto
Sub Flush(theSocket As TCPSocket)
  #Pragma BackgroundTasks False

  While True
    theSocket.Poll
    If theSocket.LastErrorCode <> 0 Then
      Exit While
    End If
    If theSocket.BytesLeftToSend <= 0 Then
      Exit While
    End If
  Wend
End Sub
```

> [@300467:@David Graham](#):
>
> Why would this crash the IDE?

The flush method isn’t yielding time back to the debugger support code that checks to see if new commands have come in from the IDE.

> [@300467:@David Graham](#):
>
> Is this a bug in Xojo?

Possibly! I’ve not seen this locally to go about tracking it down.

---

<div class="post-metadata">

**Author:** ![TimStreater](https://forum.xojo.com/user_avatar/forum.xojo.com/timstreater/32/586_2.png) [@TimStreater](https://forum.xojo.com/u/TimStreater)\
**Post date:** [September 23, 2017, 2:53pm UTC](https://forum.xojo.com/t/tcpsocket-flush-lockup/34677/3 "2017-09-23T14:53:26Z")

</div>

You should add a check thus:

```auto
if (theSocket.isConnected=False) then exit while
```

Otherwise an app will loop in flush if the remote end drops the connection. This could easily happen if, for example, the computer sleeps while the app is running and then wakes up later. I’ve had this issue and will have to wrap flush with the test above.

---

<div class="post-metadata">

**Author:** ![DerkJ](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@DerkJ](https://forum.xojo.com/u/DerkJ)\
**Post date:** [September 23, 2017, 5:05pm UTC](https://forum.xojo.com/t/tcpsocket-flush-lockup/34677/4 "2017-09-23T17:05:38Z")

</div>

I’ve had some issues using tcpsocket.Flush too. Removed the lines and it worked again. (MacOS) by reading this i suspect a bug not sure though.

---

<div class="post-metadata">

**Author:** ![TimStreater](https://forum.xojo.com/user_avatar/forum.xojo.com/timstreater/32/586_2.png) [@TimStreater](https://forum.xojo.com/u/TimStreater)\
**Post date:** [October 17, 2017, 4:41pm UTC](https://forum.xojo.com/t/tcpsocket-flush-lockup/34677/5 "2017-10-17T16:41:07Z")

</div>

[quote=303934:@Joe Ranieri]TCPSocket.Flush is basically implemented like this:

```auto
Sub Flush(theSocket As TCPSocket)
  #Pragma BackgroundTasks False

  While True
    theSocket.Poll
    If theSocket.LastErrorCode <> 0 Then
      Exit While
    End If
    If theSocket.BytesLeftToSend <= 0 Then
      Exit While
    End If
  Wend
End Sub
```

[/quote]

Are you saying that this is effectively what it is (with the above being pseudo-code), or actually what it is?

See, the doc for socket.flush says that the purpose of calling it is to force out any data now in the send buffer immediately. That’s why I call it. There’s nothing in the above (as far as I know) that forces data out. Unless that is what socket.poll does - but the documentation for that is content-free so I can’t tell.

I would appreciate some elucidation.

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [October 17, 2017, 7:41pm UTC](https://forum.xojo.com/t/tcpsocket-flush-lockup/34677/6 "2017-10-17T19:41:00Z")

</div>

All flush does is to wait till everything is done.

When you call write, the data is copied to the OS send buffer and than the method returns. Data is send automatically in background. Poll just checks status on this and calls events and updates properties.

---

<div class="post-metadata">

**Author:** ![TimStreater](https://forum.xojo.com/user_avatar/forum.xojo.com/timstreater/32/586_2.png) [@TimStreater](https://forum.xojo.com/u/TimStreater)\
**Post date:** [October 17, 2017, 8:19pm UTC](https://forum.xojo.com/t/tcpsocket-flush-lockup/34677/7 "2017-10-17T20:19:03Z")

</div>

[quote=354748:@Christian Schmitz]All flush does is to wait till everything is done.

When you call write, the data is copied to the OS send buffer and than the method returns. Data is send automatically in background. Poll just checks status on this and calls events and updates properties.[/quote]  
Thank you. That’s useful information.

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 6:33pm UTC](https://forum.xojo.com/t/tcpsocket-flush-lockup/34677/8 "2020-10-29T18:33:51Z")

</div>


