Check the output of the dmesg
command on the raspberry pi.
I get something like:
[ 296.768548] ------------[ cut here ]------------
[ 296.768576] WARNING: CPU: 3 PID: 40 at drivers/tty/tty_port.c:257 tty_port_put+0x94/0x98
[ 296.768586] Modules linked in: rfcomm cmac bnep hci_uart btbcm serdev bluetooth ecdh_generic 8021q garp stp llc brcmfmac brcmutil bcm2835_codec(C) bcm2835_v4l2(C) v4l2_mem2mem sha256_generic bcm2835_mmal_vchiq(C) v4l2_common videobuf2_vmalloc videobuf2_dma_contig videobuf2_memops cfg80211 videobuf2_v4l2 videobuf2_common videodev media rfkill vc_sm_cma(C) v3d vc4 gpu_sched drm_kms_helper rpivid_mem raspberrypi_hwmon hwmon drm drm_panel_orientation_quirks snd_soc_core snd_bcm2835(C) snd_compress snd_pcm_dmaengine snd_pcm snd_timer syscopyarea sysfillrect sysimgblt fb_sys_fops snd rpi_backlight rpi_ft5406 uio_pdrv_genirq uio evdev joydev ip_tables x_tables ipv6
[ 296.768773] CPU: 3 PID: 40 Comm: kworker/3:1 Tainted: G C 4.19.97-v7l+ #1294
[ 296.768781] Hardware name: BCM2835
[ 296.768798] Workqueue: events release_one_tty
[ 296.768825] [<c0212e04>] (unwind_backtrace) from [<c020d5e0>] (show_stack+0x20/0x24)
[ 296.768844] [<c020d5e0>] (show_stack) from [<c09b15c8>] (dump_stack+0xe0/0x124)
[ 296.768865] [<c09b15c8>] (dump_stack) from [<c0222544>] (__warn+0x104/0x11c)
[ 296.768883] [<c0222544>] (__warn) from [<c0222694>] (warn_slowpath_null+0x50/0x58)
[ 296.768899] [<c0222694>] (warn_slowpath_null) from [<c06cab28>] (tty_port_put+0x94/0x98)
[ 296.768941] [<c06cab28>] (tty_port_put) from [<bf9dd2a0>] (rfcomm_tty_cleanup+0x5c/0x60 [rfcomm])
[ 296.768999] [<bf9dd2a0>] (rfcomm_tty_cleanup [rfcomm]) from [<c06c2a38>] (release_one_tty+0x3c/0xac)
[ 296.769019] [<c06c2a38>] (release_one_tty) from [<c023e028>] (process_one_work+0x170/0x458)
[ 296.769036] [<c023e028>] (process_one_work) from [<c023e36c>] (worker_thread+0x5c/0x5a4)
[ 296.769051] [<c023e36c>] (worker_thread) from [<c02446a0>] (kthread+0x138/0x168)
[ 296.769066] [<c02446a0>] (kthread) from [<c02010ac>] (ret_from_fork+0x14/0x28)
[ 296.769075] Exception stack(0xefab3fb0 to 0xefab3ff8)
[ 296.769086] 3fa0: 00000000 00000000 00000000 00000000
[ 296.769098] 3fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[ 296.769108] 3fe0: 00000000 00000000 00000000 00000000 00000013 00000000
[ 296.769119] ---[ end trace 545b669f95e0d2b5 ]---
Which makes me believe the kernel module (rfcomm) and its processing thread (krfcomm) have hung/crash while releasing the tty, and left it in a broken state.
As a result, attempts to create new one conflict with the one which has not yet been deleted, while attempts to delete/release the existing one result in a message saying the device doesnt exists.
I don't believe there is a solution at this moment, other than rebooting.
I read somewhere that if you ensure the connection remains open for more than 10 seconds, the crash doesn't occur and the port can be reused successfully.
Edit:
The following answer to the same question on SO suggests removing the modemmanager
package, which may be interfering.
https://stackoverflow.com/a/46915801/3398351