Here is a stack trace I got when removing a device from a raid1 filesystem. I have run a check on the filesystem and I got no errors, just a message about the free space tree needing to be rebuilt, which I did on mount.
[ 1569.185720] BTRFS info (device dm-5): relocating block group 7042797404160 flags metadata|raid1 [ 1635.157948] BTRFS info (device dm-5): found 32629 extents [ 1643.277714] BTRFS info (device dm-5): relocating block group 7043971809280 flags system|raid1 [ 1643.577339] BTRFS info (device dm-5): found 36 extents [ 1643.878316] BTRFS info (device dm-5): relocating block group 7044005363712 flags system|raid1 [ 1644.403175] BTRFS info (device dm-5): found 35 extents [ 1645.268105] BTRFS info (device dm-5): relocating block group 7039576178688 flags data|raid1 [ 1645.959683] ------------[ cut here ]------------ [ 1645.959684] kernel BUG at fs/btrfs/relocation.c:1413! [ 1645.959695] invalid opcode: 0000 [#1] PREEMPT SMP NOPTI [ 1645.959720] CPU: 0 PID: 10402 Comm: btrfs Not tainted 5.1.4-gentoo #2 [ 1645.959745] Hardware name: Gigabyte Technology Co., Ltd. To be filled by O.E.M./B75M-D3H, BIOS F15 10/23/2013 [ 1645.959778] RIP: 0010:create_reloc_root+0x1f0/0x200 [ 1645.959801] Code: c7 85 dc 00 00 00 00 00 00 00 48 c7 85 e4 00 00 00 00 00 00 00 c6 85 ec 00 00 00 00 c6 85 ed 00 00 00 00 e9 00 ff ff ff 0f 0b <0f> 0b 0f 0b 0f 0b 0f 0b e8 73 07 d9 ff 0f 1f 00 49 89 f9 48 89 d7 [ 1645.959844] RSP: 0018:ffffc90000043838 EFLAGS: 00010282 [ 1645.959867] RAX: 00000000ffffffef RBX: ffff8885ff9a9800 RCX: 0000000000000001 [ 1645.959893] RDX: 0000000000000010 RSI: ffff888541736460 RDI: ffff888602445e00 [ 1645.959918] RBP: ffff8885ff899400 R08: ffff888570a50508 R09: ffffc90000043658 [ 1645.959944] R10: 0000000000000049 R11: 0000000000000000 R12: ffff8885fb705e38 [ 1645.959970] R13: fffffffffffffff7 R14: ffff8885ef3f8000 R15: ffff8885ef3f8000 [ 1645.959996] FS: 00007f1d5b7868c0(0000) GS:ffff888606000000(0000) knlGS:0000000000000000 [ 1645.960024] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 1645.960047] CR2: 000055b26a74f7f0 CR3: 00000005a5f3e004 CR4: 00000000000606b0 [ 1645.960073] Call Trace: [ 1645.960094] btrfs_init_reloc_root+0x56/0xa0 [ 1645.960118] record_root_in_trans+0xa7/0xd0 [ 1645.960140] btrfs_record_root_in_trans+0x4a/0x60 [ 1645.960173] start_transaction+0x96/0x410 [ 1645.960206] __btrfs_prealloc_file_range+0xba/0x450 [ 1645.960239] ? btrfs_alloc_data_chunk_ondemand+0x1f5/0x230 [ 1645.960274] btrfs_prealloc_file_range+0xb/0x10 [ 1645.960306] prealloc_file_extent_cluster+0x117/0x240 [ 1645.960340] relocate_file_extent_cluster+0x90/0x4b0 [ 1645.960373] relocate_data_extent+0x5d/0xd0 [ 1645.960405] relocate_block_group+0x277/0x600 [ 1645.960437] btrfs_relocate_block_group+0x154/0x220 [ 1645.960470] btrfs_relocate_chunk+0x2c/0xa0 [ 1645.960502] btrfs_shrink_device+0x1dc/0x540 [ 1645.960533] ? btrfs_find_device_by_devspec+0x140/0x1d0 [ 1645.960566] btrfs_rm_device+0x11c/0x50e [ 1645.960598] btrfs_ioctl+0x2a08/0x2de0 [ 1645.960631] ? mem_cgroup_commit_charge+0x69/0x420 [ 1645.960664] ? mem_cgroup_try_charge+0x88/0x1d0 [ 1645.960697] ? _copy_to_user+0x28/0x30 [ 1645.960729] ? cp_new_stat+0x126/0x160 [ 1645.960760] ? do_vfs_ioctl+0x3e6/0x640 [ 1645.960790] do_vfs_ioctl+0x3e6/0x640 [ 1645.960822] ? __se_sys_newstat+0x48/0x70 [ 1645.960853] ksys_ioctl+0x35/0x70 [ 1645.960883] __x64_sys_ioctl+0x11/0x20 [ 1645.960915] do_syscall_64+0x43/0xf0 [ 1645.960948] entry_SYSCALL_64_after_hwframe+0x44/0xa9 [ 1645.960981] RIP: 0033:0x7f1d5b9ca047 [ 1645.961011] Code: 00 00 00 75 0c 48 c7 c0 ff ff ff ff 48 83 c4 18 c3 e8 8d d0 01 00 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 00 b8 10 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 19 ce 0c 00 f7 d8 64 89 01 48 [ 1645.961084] RSP: 002b:00007ffc2285cc18 EFLAGS: 00000206 ORIG_RAX: 0000000000000010 [ 1645.961120] RAX: ffffffffffffffda RBX: 00007ffc2285ede0 RCX: 00007f1d5b9ca047 [ 1645.961156] RDX: 00007ffc2285cc50 RSI: 000000005000943a RDI: 0000000000000003 [ 1645.961191] RBP: 00005634b8aa5110 R08: 0000000000000000 R09: 0000000000000000 [ 1645.961227] R10: 00005634b89dac68 R11: 0000000000000206 R12: 0000000000000003 [ 1645.961262] R13: 00007ffc2285cc50 R14: 0000000000000000 R15: 0000000000000000 [ 1645.961298] Modules linked in: ipt_MASQUERADE xt_nat xt_recent xt_comment ipt_REJECT nf_reject_ipv4 xt_addrtype iptable_nat xt_mark iptable_mangle xt_TCPMSS xt_CT iptable_raw xt_multiport xt_conntrack xt_NFLOG nf_nat_tftp nf_nat_snmp_basic nf_conntrack_snmp asn1_decoder nf_nat_sip nf_nat_pptp nf_nat_irc nf_nat_h323 nf_nat_ftp nf_nat_amanda ts_kmp nf_conntrack_amanda nf_nat nf_conntrack_sane nf_conntrack_tftp nf_conntrack_sip nf_conntrack_pptp nf_conntrack_netlink nf_conntrack_netbios_ns nf_conntrack_broadcast nf_conntrack_irc nf_conntrack_h323 nf_conntrack_ftp iptable_filter ip_tables nfsd auth_rpcgss oid_registry nfs_acl binfmt_misc intel_powerclamp pcspkr coretemp i2c_i801 k10temp it87 lpc_ich mfd_core hwmon_vid xts cbc ixgb macvlan r8169 libphy igb dca i2c_algo_bit e1000 atl1c loop fuse nfs lockd grace sunrpc linear raid10 raid456 async_raid6_recov async_memcpy async_pq async_xor async_tx raid1 raid0 md_mod dm_snapshot dm_mirror dm_region_hash dm_log dm_cache_smq hid_sunplus hid_sony [ 1645.961320] hid_samsung hid_pl hid_petalynx hid_gyration usbhid xhci_pci xhci_hcd ohci_hcd uhci_hcd usb_storage ehci_pci ehci_hcd mpt3sas hpsa mptsas scsi_transport_sas mptspi scsi_transport_spi mptscsih mptbase sata_inic162x ata_piix ahci libahci sata_nv sata_sil24 pata_jmicron pata_amd pata_mpiix nvme nvme_core [ 1645.962169] ---[ end trace 0497f2210bcbbb57 ]--- [ 1645.962219] RIP: 0010:create_reloc_root+0x1f0/0x200 [ 1645.962253] Code: c7 85 dc 00 00 00 00 00 00 00 48 c7 85 e4 00 00 00 00 00 00 00 c6 85 ec 00 00 00 00 c6 85 ed 00 00 00 00 e9 00 ff ff ff 0f 0b <0f> 0b 0f 0b 0f 0b 0f 0b e8 73 07 d9 ff 0f 1f 00 49 89 f9 48 89 d7 [ 1645.962343] RSP: 0018:ffffc90000043838 EFLAGS: 00010282 [ 1645.962385] RAX: 00000000ffffffef RBX: ffff8885ff9a9800 RCX: 0000000000000001 [ 1645.962431] RDX: 0000000000000010 RSI: ffff888541736460 RDI: ffff888602445e00 [ 1645.962490] RBP: ffff8885ff899400 R08: ffff888570a50508 R09: ffffc90000043658 [ 1645.962491] R10: 0000000000000049 R11: 0000000000000000 R12: ffff8885fb705e38 [ 1645.962492] R13: fffffffffffffff7 R14: ffff8885ef3f8000 R15: ffff8885ef3f8000 [ 1645.962493] FS: 00007f1d5b7868c0(0000) GS:ffff888606000000(0000) knlGS:0000000000000000 [ 1645.962494] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 1645.962495] CR2: 000055b26a74f7f0 CR3: 00000005a5f3e004 CR4: 00000000000606b0