Verified Commit 81e6cfd6 authored by aguestuser's avatar aguestuser

[hf] pass tx to events.log correctly to fix registrar.destroy

* BUG SYMPTOM: phoneNumberRegistrar.destroy is hanging while trying to
  destroy the channel
* CAUSE: not clear but likely something going on with deadlock. we'd
  assumed it was something to do with the call to `channel.destroy`,
  but perhaps it is in fact to do with the call to
  `eventsRepository.log`, which was passing `transaction` as an
  attribute to the event it was creating, and not as an option
* FIX: try correcting the syntax to see if it elimiantes the timeout
parent 82c51a64
Pipeline #46190 failed with stage
in 1 minute and 19 seconds
......@@ -33,11 +33,9 @@ const update = (phoneNumber, attrs) =>
.then(([, [pNumInstance]]) => pNumInstance)
// (string, Transaction | null) => Promise<boolean>
const destroy = async (phoneNumber, transaction) => {
const destroy = async (phoneNumber, transaction = null) => {
const channel = await findByPhoneNumber(phoneNumber)
return channel
? channel.destroy({ ...(transaction ? { transaction } : {}) }).then(() => true)
: false
return channel ? channel.destroy({ transaction }).then(() => true) : false
}
const findAll = () => app.db.channel.findAll()
......
......@@ -4,12 +4,15 @@ const { sha256Hash } = require('../../util')
// (string, string, sequelize.Transaction | null) => Promise<Event>
const log = (eventType, phoneNumber, transaction = null) =>
app.db.event.create({
type: eventType,
phoneNumberHash: sha256Hash(phoneNumber),
// omit the transaction k/v pair if no transaction arg provided
...(transaction ? { transaction } : {}),
})
app.db.event.create(
{
type: eventType,
phoneNumberHash: sha256Hash(phoneNumber),
},
{
transaction,
},
)
// string => Promise<Event|null>
const logIfFirstMembership = async memberPhoneNumber => {
......
......@@ -11,11 +11,9 @@ const create = ({ phoneNumber, twilioSid, status }) =>
app.db.phoneNumber.create({ phoneNumber, twilioSid, status })
// (string, Transaction | null) => Promise<boolean>
const destroy = async (phoneNumber, transaction) => {
const destroy = async (phoneNumber, transaction = null) => {
const phoneNumberRecord = await find(phoneNumber)
return phoneNumberRecord
? phoneNumberRecord.destroy({ ...(transaction ? { transaction } : {}) }).then(() => true)
: false
return phoneNumberRecord ? phoneNumberRecord.destroy({ transaction }).then(() => true) : false
}
const find = phoneNumber => app.db.phoneNumber.findOne({ where: { phoneNumber } })
......
const { Transaction } = require('sequelize')
const app = require('../../index')
const phoneNumberRepository = require('../../db/repositories/phoneNumber')
const { defaultLanguage } = require('../../config')
......@@ -19,9 +18,7 @@ const {
// ({phoneNumber: string, sender?: string }) -> SignalboostStatus
const destroy = async ({ phoneNumber, sender }) => {
let tx = await app.db.sequelize.transaction({
isolationLevel: Transaction.ISOLATION_LEVELS.READ_UNCOMMITTED,
})
const tx = await app.db.sequelize.transaction()
try {
const channel = await channelRepository.findDeep(phoneNumber)
......@@ -40,14 +37,17 @@ const destroy = async ({ phoneNumber, sender }) => {
if (channel) {
logger.log(`deleting channel ${phoneNumber}...`)
await channelRepository.destroy(channel.phoneNumber, tx)
await eventRepository.log(eventTypes.CHANNEL_DESTROYED, phoneNumber, tx)
logger.log(`...deleted channel ${phoneNumber}`)
// notify members in the background
logger.log(`logging destruction of ${phoneNumber}...`)
await eventRepository.log(eventTypes.CHANNEL_DESTROYED, phoneNumber, tx)
logger.log(`...logged destruction of ${phoneNumber}`)
logger.log(`sending deletion notice to members of: ${phoneNumber}...`)
// notify members in the background
notifier
.notifyMembersExcept(channel, sender, notificationKeys.CHANNEL_DESTROYED)
.then(() => logger.log(`...sent deltion notice to members of: ${phoneNumber}`))
.then(() => logger.log(`...sent deletion notice to members of: ${phoneNumber}`))
.catch(logger.error)
}
......
......@@ -7,6 +7,9 @@ import channelRepository, { isSysadmin } from '../../../../app/db/repositories/c
import app from '../../../../app'
import testApp from '../../../support/testApp'
import dbService from '../../../../app/db'
import { wait } from '../../../../app/util'
import { membershipFactory } from '../../../support/factories/membership'
import * as phoneNumberRegistrar from '../../../../app/registrar/phoneNumber'
const {
signal: { supportPhoneNumber },
} = require('../../../../app/config')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment