Description
When a stream gets a DataFrame
and nothing reads data from the stream of the connection, it can't close the connection and leads to memory leak.
When I'm working on https://github.com/cri-o/cri-o memory leak issue, I found that in the situation above, spdy stream server causes memory leak.
The leak happens when it tries to close the connection, and it waits wg.Wait()
forever.
Lines 392 to 394 in 57d1ca2
The cause of the issue is that it can't finish frameHandler()
because of the deadlock.
There are some workers calling frameHandler()
, and wg.Add()
when each worker starts and wg.Done()
when each worker is done.
Lines 317 to 333 in 57d1ca2
DataFrame
s queued in a PriorityFrameQueue
are processed in frameHandler()
and if it is a DataFrame
, it is handled by dataFrameHandler()
( = handleDataFrame()
).
In the function, it blocks until either the stream is closed or something reads the stream dataChan
(e.g. something calls Read()
or ReadData()
)
Otherwise the function can't finish, which means frameHandler()
also can't finish, and it never calls wg.Done()
.
Lines 598 to 607 in 57d1ca2
If nothing reads the data from the stream, the only way of blocking it is to close the stream.
However streams in a connection are closed after wg.Wait()
.
Lines 394 to 409 in 57d1ca2
The simplest fix is to move stream.closeRemoteChannels()
before wg.Wait()
, but I'm unsure if it causes other race condition errors.