Kernel restart fails on docker jupyterlab

Hello,

I’m building jupyterlab on docker and I’m running into an issue where kernel (Python 3 ipykernel) restart hangs forever with the following error:

Interestingly, when I shut down the kernel first and then restart it, then it’s completed. I did some research and this has been a known issue but it was resolved, and the image that I’m building on has the resolution (I pulled the image and ran it locally to verify). But somehow I’m reintroducing the error with the way I’m building the docker image.

To give more context, I’m using both jupyterhub (for authentication) and jupyterlab (for notebook).
Upon login, I use docker spawner to create jupyterlab container based on my dockerfile.
To the jupyterlab dockerfile I add matlab integration and some other python packages.

Please let me know how I can investigate further/resolve this issue. Thank you!

Attached error log below

info 15:5:44.941: Restart requested file:///c%3A/local_repo/Graphing/DCIR_plots/v2_plot_DCIR.ipynb
info 15:5:44.942: Restart kernel execution
info 15:5:44.942: Cancel pending cells
error 15:5:45.64: Restart failed c:\local_repo\Graphing\DCIR_plots\v2_plot_DCIR.ipynb [a [Error]: Invalid response: 502 Bad Gateway
	at Function.create (c:\Users\ythayabaran1\.vscode\extensions\ms-toolsai.jupyter-2022.7.1102252217\out\node_modules\@jupyterlab\services.js:2:53448)
	at processTicksAndRejections (node:internal/process/task_queues:96:5)
	at async Object.a.restartKernel (c:\Users\ythayabaran1\.vscode\extensions\ms-toolsai.jupyter-2022.7.1102252217\out\node_modules\@jupyterlab\services.js:2:41928)
	at async y.restart (c:\Users\ythayabaran1\.vscode\extensions\ms-toolsai.jupyter-2022.7.1102252217\out\node_modules\@jupyterlab\services.js:2:21669)
	at async w.restart (c:\Users\ythayabaran1\.vscode\extensions\ms-toolsai.jupyter-2022.7.1102252217\out\extension.node.js:2:1920728)
	at async t.KernelExecution.restartExecution (c:\Users\ythayabaran1\.vscode\extensions\ms-toolsai.jupyter-2022.7.1102252217\out\extension.node.js:2:2002663)] {
  response: F [Response] {
    size: 0,
    timeout: 0,
    [Symbol(Body internals)]: { body: [PassThrough], disturbed: true, error: null },
    [Symbol(Response internals)]: {
      url: 'generic_url',
      status: 502,
      statusText: 'Bad Gateway',
      headers: [x [Headers]],
      counter: 0
    }
  },
  traceback: ''
}
warn 15:5:45.66: Error occurred while trying to restart the kernel, options.disableUI=false [a [Error]: Invalid response: 502 Bad Gateway
	at Function.create (c:\Users\ythayabaran1\.vscode\extensions\ms-toolsai.jupyter-2022.7.1102252217\out\node_modules\@jupyterlab\services.js:2:53448)
	at processTicksAndRejections (node:internal/process/task_queues:96:5)
	at async Object.a.restartKernel (c:\Users\ythayabaran1\.vscode\extensions\ms-toolsai.jupyter-2022.7.1102252217\out\node_modules\@jupyterlab\services.js:2:41928)
	at async y.restart (c:\Users\ythayabaran1\.vscode\extensions\ms-toolsai.jupyter-2022.7.1102252217\out\node_modules\@jupyterlab\services.js:2:21669)
	at async w.restart (c:\Users\ythayabaran1\.vscode\extensions\ms-toolsai.jupyter-2022.7.1102252217\out\extension.node.js:2:1920728)
	at async t.KernelExecution.restartExecution (c:\Users\ythayabaran1\.vscode\extensions\ms-toolsai.jupyter-2022.7.1102252217\out\extension.node.js:2:2002663)] {
  response: F [Response] {
    size: 0,
    timeout: 0,
    [Symbol(Body internals)]: { body: [PassThrough], disturbed: true, error: null },
    [Symbol(Response internals)]: {
      url: 'generic_url',
      status: 502,
      statusText: 'Bad Gateway',
      headers: [x [Headers]],
      counter: 0
    }
  },
  traceback: ''
}
warn 15:5:45.66: Kernel Error, context = restart [a [Error]: Invalid response: 502 Bad Gateway
	at Function.create (c:\Users\ythayabaran1\.vscode\extensions\ms-toolsai.jupyter-2022.7.1102252217\out\node_modules\@jupyterlab\services.js:2:53448)
	at processTicksAndRejections (node:internal/process/task_queues:96:5)
	at async Object.a.restartKernel (c:\Users\ythayabaran1\.vscode\extensions\ms-toolsai.jupyter-2022.7.1102252217\out\node_modules\@jupyterlab\services.js:2:41928)
	at async y.restart (c:\Users\ythayabaran1\.vscode\extensions\ms-toolsai.jupyter-2022.7.1102252217\out\node_modules\@jupyterlab\services.js:2:21669)
	at async w.restart (c:\Users\ythayabaran1\.vscode\extensions\ms-toolsai.jupyter-2022.7.1102252217\out\extension.node.js:2:1920728)
	at async t.KernelExecution.restartExecution (c:\Users\ythayabaran1\.vscode\extensions\ms-toolsai.jupyter-2022.7.1102252217\out\extension.node.js:2:2002663)] {
  response: F [Response] {
    size: 0,
    timeout: 0,
    [Symbol(Body internals)]: { body: [PassThrough], disturbed: true, error: null },
    [Symbol(Response internals)]: {
      url: 'generic_url',
      status: 502,
      statusText: 'Bad Gateway',
      headers: [x [Headers]],
      counter: 0
    }
  },
  traceback: ''
}
info 15:5:45.82: Dispose Kernel 'c:\local_repo\Graphing\DCIR_plots\v2_plot_DCIR.ipynb' associated with 'c:\local_repo\Graphing\DCIR_plots\v2_plot_DCIR.ipynb'
info 15:5:45.83: Cancel pending cells