You will be redirected in 30 seconds or close now.

ColdFusion Authors: Yakov Fain, Jeremy Geelan, Maureen O'Gara, Nancy Y. Nee, Tad Anderson

Related Topics: ColdFusion, Adobe Flex

ColdFusion: Article

ColdFusion Developer's Journal - The Dark Side of Event Gateways

How to cope with a sort of denial of service attack from the inside

Gateways; you've heard about them. You've read the hype. You've probably created one or two. You've seen applications do wonderful things with them. There have been articles written about them.

 Don't be fooled. Not everything is always the way it seems. There's a dark side to the gateway system. A side where things don't go as expected.

I think the gateway system is like an exotic sports car with a child at the wheel. It is full of power, has extensive form and tons of function. But it seems like someone with no knowledge or understanding is at the controls.

Gateways can be very powerful; so powerful that they can flood a server from the inside creating what could be called a sort of denial of service attack from the inside. It's obviously not an attack but the effect is about the same. The server becomes overloaded handling gateway requests and can run out of resources to handle normal traffic.

This usually occurs when you have multiple gateways and they all start firing at the same time. It can even be caused by an asynchronous gateway that's repeatedly fired and doesn't terminate. You can even have a condition where you have hung gateways that aren't terminating.

Due to the nature of gateways there's no easy way to recover from this. Your only recourse is to restart the ColdFusion service. Although restarting the service will fix the problem, you'll have lost whatever was running at restart. You could end up with corrupt data or a whole slew of other issues.

My goal is to help you take control of the gateway system. I'm going to show you how to put a "Gatekeeper" on top of gateways; a method in which all gateway requests are queued. Once queued they can be controlled better and prevent the gateways from overrunning the server. But creating a "Gatekeeper" won't save you from crashes.

The amount of work is minimal. All you need to do is modify your existing gateway cfcs. Just a couple of minor tweaks to your current cfcs and you'll be off and running.
The queue system has two parts: the "Gatekeeper" and a "Dispatcher." They each have their own job but work together to create the queue. Once you actually have this you can create a monitor to keep tabs on everything. This article won't cover this part but the online code contains code for a monitor.
The Gatekeeper takes incoming gateway requests and converts them to server vars that will be used by the Dispatcher and the Monitor. The Dispatcher takes the server vars created by the Gatekeeper and creates asynchronous calls to the appropriate cfcs. The Monitor does just what its name suggests. It keeps tabs on the jobs running and will stop the processing of new requests if things go badly.

The final part is the original gateway cfcs themselves. They need a slight alteration that will let them work with the queue. It starts with the alterations to the current gateway cfcs. The code in Listing 1 demonstrates the code changes needed. Copy the onAdd function and create a new function called GKonAdd. Then the onAdd event is altered to send the event to the Gatekeeper.

Listing 2 is the Gatekeeper itself. All it does is take the event passed to it and stores it in a server variable called "server.cfcevents." You can use either the application or the server scope for this. However, if you use application you have to deal with application timeouts.

The Gatekeeper creates a structure for each gateway that's using it. The structure name is based on the gateway id from the CF administrator. After adding the structure it then fires the Dispatcher asynchronous gateway. You'll have to create this gateway in the CF administrator.

The Dispatcher has a case for each gateway event as well as how many concurrent requests can be running. The Dispatcher is designed to run forever once it starts. It contains code to make it pause as well as detect if it's already running when it starts. If a Dispatcher instance is already running the new instance will shut down. The code for the Dispatcher is very involved and lengthy so it's not in this article but it is available online.
Once you have the Dispatcher set up for your gateways you're ready to go. If you need to you can also set up special conditions in the Dispatcher that will let a request be run immediately and bypass the queue.

Unfortunately I haven't figured out how to do crash recovery. You could write events to a text file instead of the application or server scope. However, then you're limited as to what data you can store. This also adds excess overhead.

And there you have it. You're now back in control of your system. You no longer have to worry about your gateways taking over your system. Hopefully in the future functionality like this will be core to CF and a workaround like this won't be necessary. But until then we have to do what we can to remain in control of our systems.

More Stories By Dave Ferguson

Dave Ferguson is a system architect and principal programmer. He has been doing website design and development for over 10 years. He is also a Certified Advanced ColdFusion Developer. You can read his blog at http://dfoncf.blogspot.com

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.

IoT & Smart Cities Stories
Whenever a new technology hits the high points of hype, everyone starts talking about it like it will solve all their business problems. Blockchain is one of those technologies. According to Gartner's latest report on the hype cycle of emerging technologies, blockchain has just passed the peak of their hype cycle curve. If you read the news articles about it, one would think it has taken over the technology world. No disruptive technology is without its challenges and potential impediments t...
Nicolas Fierro is CEO of MIMIR Blockchain Solutions. He is a programmer, technologist, and operations dev who has worked with Ethereum and blockchain since 2014. His knowledge in blockchain dates to when he performed dev ops services to the Ethereum Foundation as one the privileged few developers to work with the original core team in Switzerland.
Andrew Keys is Co-Founder of ConsenSys Enterprise. He comes to ConsenSys Enterprise with capital markets, technology and entrepreneurial experience. Previously, he worked for UBS investment bank in equities analysis. Later, he was responsible for the creation and distribution of life settlement products to hedge funds and investment banks. After, he co-founded a revenue cycle management company where he learned about Bitcoin and eventually Ethereal. Andrew's role at ConsenSys Enterprise is a mul...
René Bostic is the Technical VP of the IBM Cloud Unit in North America. Enjoying her career with IBM during the modern millennial technological era, she is an expert in cloud computing, DevOps and emerging cloud technologies such as Blockchain. Her strengths and core competencies include a proven record of accomplishments in consensus building at all levels to assess, plan, and implement enterprise and cloud computing solutions. René is a member of the Society of Women Engineers (SWE) and a m...
If a machine can invent, does this mean the end of the patent system as we know it? The patent system, both in the US and Europe, allows companies to protect their inventions and helps foster innovation. However, Artificial Intelligence (AI) could be set to disrupt the patent system as we know it. This talk will examine how AI may change the patent landscape in the years to come. Furthermore, ways in which companies can best protect their AI related inventions will be examined from both a US and...
In his general session at 19th Cloud Expo, Manish Dixit, VP of Product and Engineering at Dice, discussed how Dice leverages data insights and tools to help both tech professionals and recruiters better understand how skills relate to each other and which skills are in high demand using interactive visualizations and salary indicator tools to maximize earning potential. Manish Dixit is VP of Product and Engineering at Dice. As the leader of the Product, Engineering and Data Sciences team at D...
Bill Schmarzo, Tech Chair of "Big Data | Analytics" of upcoming CloudEXPO | DXWorldEXPO New York (November 12-13, 2018, New York City) today announced the outline and schedule of the track. "The track has been designed in experience/degree order," said Schmarzo. "So, that folks who attend the entire track can leave the conference with some of the skills necessary to get their work done when they get back to their offices. It actually ties back to some work that I'm doing at the University of San...
When talking IoT we often focus on the devices, the sensors, the hardware itself. The new smart appliances, the new smart or self-driving cars (which are amalgamations of many ‘things'). When we are looking at the world of IoT, we should take a step back, look at the big picture. What value are these devices providing. IoT is not about the devices, its about the data consumed and generated. The devices are tools, mechanisms, conduits. This paper discusses the considerations when dealing with the...
Bill Schmarzo, author of "Big Data: Understanding How Data Powers Big Business" and "Big Data MBA: Driving Business Strategies with Data Science," is responsible for setting the strategy and defining the Big Data service offerings and capabilities for EMC Global Services Big Data Practice. As the CTO for the Big Data Practice, he is responsible for working with organizations to help them identify where and how to start their big data journeys. He's written several white papers, is an avid blogge...
Dynatrace is an application performance management software company with products for the information technology departments and digital business owners of medium and large businesses. Building the Future of Monitoring with Artificial Intelligence. Today we can collect lots and lots of performance data. We build beautiful dashboards and even have fancy query languages to access and transform the data. Still performance data is a secret language only a couple of people understand. The more busine...