Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TDP/RDP termination #13912

Merged
merged 5 commits into from
Jun 30, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions lib/srv/desktop/rdp/rdpclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func New(ctx context.Context, cfg Config) (*Client, error) {
}

// Run starts the rdp client and blocks until the client disconnects,
// then runs the cleanup.
// then ensures the cleanup is run.
func (c *Client) Run(ctx context.Context) error {
defer c.close()

Expand Down Expand Up @@ -256,6 +256,7 @@ func (c *Client) start() {
c.wg.Add(1)
go func() {
defer c.wg.Done()
defer c.close()
defer c.cfg.Log.Info("RDP output streaming finished")

// C.read_rdp_output blocks for the duration of the RDP connection and
Expand All @@ -275,7 +276,9 @@ func (c *Client) start() {
c.wg.Add(1)
go func() {
defer c.wg.Done()
defer c.close()
defer c.cfg.Log.Info("TDP input streaming finished")

// Remember mouse coordinates to send them with all CGOPointer events.
var mouseX, mouseY uint32
for {
Expand Down Expand Up @@ -521,16 +524,21 @@ func (c *Client) sharedDirectoryInfoRequest(req tdp.SharedDirectoryInfoRequest)
// and frees the Rust client.
func (c *Client) close() {
c.closeOnce.Do(func() {
// Close the RDP client
if err := C.close_rdp(c.rustClient); err != C.ErrCodeSuccess {
c.cfg.Log.Warningf("failed to close the RDP client")
// Ensure the RDP connection is closed
if errCode := C.close_rdp(c.rustClient); errCode != C.ErrCodeSuccess {
c.cfg.Log.Warningf("error closing the RDP connection")
}

// Let the Rust side free its data
C.free_rdp(c.rustClient)

// Release the memory of the cgo.Handle
c.handle.Delete()

// Ensure the TDP connection is closed
if err := c.cfg.Conn.Close(); err != nil {
c.cfg.Log.Warningf("error closing the TDP connection: %v", err)
}
})
}

Expand Down