luke-jr/bfgminer

Possible deadlock issues

ryancaicse opened this issue · 1 comments

It seems mutexp is not released before returning 422 and 427. Should it be a bug?

bfgminer/driver-modminer.c

Lines 404 to 427 in 8e0278a

mutex_lock(mutexp);
fd = modminer->device->device_fd;
if (fd == -1) {
// Died in another thread...
mutex_unlock(mutexp);
return false;
}
cmd[0] = MODMINER_GET_USERCODE;
cmd[1] = fpgaid;
if (write(fd, cmd, 2) != 2)
bailout2(LOG_ERR, "%s: Error writing (read USER code)", modminer->proc_repr);
if (serial_read(fd, buf, 4) != 4)
bailout2(LOG_ERR, "%s: Error reading (read USER code)", modminer->proc_repr);
if (memcmp(buf, BISTREAM_USER_ID, 4)) {
applog(LOG_ERR, "%s: FPGA not programmed", modminer->proc_repr);
if (!modminer_fpga_upload_bitstream(modminer))
return false;
} else if (opt_force_dev_init && !((struct modminer_fpga_state *)modminer->device->thr[0]->cgpu_data)->pdone) {
applog(LOG_DEBUG, "%s: FPGA is already programmed, but --force-dev-init is set",
modminer->proc_repr);
if (!modminer_fpga_upload_bitstream(modminer))
return false;

Similar to the below. It may occur with very low probability

bfgminer/driver-proxy.c

Lines 95 to 115 in 8e0278a

mutex_lock(&proxy_clients_mutex);
HASH_FIND_STR(proxy_clients, username, client);
if (!client)
{
user = strdup(username);
cgpu = malloc(sizeof(*cgpu));
client = malloc(sizeof(*client));
*cgpu = (struct cgpu_info){
.drv = &proxy_drv,
.set_device_funcs = proxy_set_device_funcs,
.threads = 0,
.device_data = client,
.device_path = user,
};
timer_set_now(&cgpu->cgminer_stats.start_tv);
if (unlikely(!create_new_cgpus(add_cgpu_live, cgpu)))
{
free(client);
free(cgpu);
free(user);
return NULL;